tools: update babel-eslint

This is just a minor update to use the newest latest version.

PR-URL: https://github.com/nodejs/node/pull/27670
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Refael Ackermann (רפאל פלחי) <refack@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
This commit is contained in:
Ruben Bridgewater 2019-05-13 23:47:07 +02:00
parent cddff701f8
commit a121f81510
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
53 changed files with 3739 additions and 2846 deletions

View File

@ -10,6 +10,7 @@ exports.Noop = Noop;
exports.Directive = Directive;
exports.DirectiveLiteral = DirectiveLiteral;
exports.InterpreterDirective = InterpreterDirective;
exports.Placeholder = Placeholder;
function File(node) {
if (node.program) {
@ -83,4 +84,14 @@ function DirectiveLiteral(node) {
function InterpreterDirective(node) {
this.token(`#!${node.value}\n`);
}
function Placeholder(node) {
this.token("%%");
this.print(node.name);
this.token("%%");
if (node.expectedNode === "Statement") {
this.semicolon();
}
}

View File

@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Identifier = Identifier;
exports.ArgumentPlaceholder = ArgumentPlaceholder;
exports.SpreadElement = exports.RestElement = RestElement;
exports.ObjectPattern = exports.ObjectExpression = ObjectExpression;
exports.ObjectMethod = ObjectMethod;
@ -49,6 +50,10 @@ function Identifier(node) {
});
}
function ArgumentPlaceholder() {
this.token("?");
}
function RestElement(node) {
this.token("...");
this.print(node.argument, node);

View File

@ -296,7 +296,7 @@ class Printer {
const loc = t().isProgram(node) || t().isFile(node) ? null : node.loc;
this.withSource("start", loc, () => {
this[node.type](node, parent);
printMethod.call(this, node, parent);
});
this._printTrailingComments(node);

View File

@ -5,7 +5,7 @@
},
"bundleDependencies": false,
"dependencies": {
"@babel/types": "^7.3.4",
"@babel/types": "^7.4.4",
"jsesc": "^2.5.1",
"lodash": "^4.17.11",
"source-map": "^0.5.0",
@ -14,13 +14,13 @@
"deprecated": false,
"description": "Turns an AST into code.",
"devDependencies": {
"@babel/helper-fixtures": "^7.2.0",
"@babel/parser": "^7.3.4"
"@babel/helper-fixtures": "^7.4.4",
"@babel/parser": "^7.4.4"
},
"files": [
"lib"
],
"gitHead": "1f6454cc90fe33e0a32260871212e2f719f35741",
"gitHead": "2c88694388831b1e5b88e4bbed6781eb2be1edba",
"homepage": "https://babeljs.io/",
"license": "MIT",
"main": "lib/index.js",
@ -32,5 +32,5 @@
"type": "git",
"url": "https://github.com/babel/babel/tree/master/packages/babel-generator"
},
"version": "7.3.4"
"version": "7.4.4"
}

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2014-2018 Sebastian McKenzie <sebmck@gmail.com>
Copyright (c) 2014-present Sebastian McKenzie and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View File

@ -47,7 +47,7 @@ function splitExportDeclaration(exportDeclaration) {
exportDeclaration.replaceWith(updatedDeclaration);
if (needBindingRegistration) {
scope.registerBinding(isClassDeclaration ? "let" : "var", exportDeclaration);
scope.registerDeclaration(exportDeclaration);
}
return exportDeclaration;

View File

@ -1,16 +1,20 @@
{
"bundleDependencies": false,
"dependencies": {
"@babel/types": "^7.0.0"
"@babel/types": "^7.4.4"
},
"deprecated": false,
"description": ">",
"gitHead": "2c88694388831b1e5b88e4bbed6781eb2be1edba",
"license": "MIT",
"main": "lib/index.js",
"name": "@babel/helper-split-export-declaration",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/babel/babel/tree/master/packages/babel-helper-split-export-declaration"
},
"version": "7.0.0"
"version": "7.4.4"
}

File diff suppressed because it is too large Load Diff

View File

@ -11,9 +11,9 @@
"description": "A JavaScript parser",
"devDependencies": {
"@babel/code-frame": "^7.0.0",
"@babel/helper-fixtures": "^7.2.0",
"charcodes": "0.1.0",
"unicode-11.0.0": "^0.7.8"
"@babel/helper-fixtures": "^7.4.4",
"charcodes": "^0.2.0",
"unicode-12.0.0": "^0.7.9"
},
"engines": {
"node": ">=6.0.0"
@ -23,7 +23,7 @@
"lib",
"typings"
],
"gitHead": "1f6454cc90fe33e0a32260871212e2f719f35741",
"gitHead": "33ab4f166117e2380de3955a0842985f578b01b8",
"homepage": "https://babeljs.io/",
"keywords": [
"babel",
@ -44,5 +44,5 @@
"url": "https://github.com/babel/babel/tree/master/packages/babel-parser"
},
"types": "typings/babel-parser.d.ts",
"version": "7.3.4"
"version": "7.4.5"
}

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2014-2018 Sebastian McKenzie and other contributors
Copyright (c) 2014-present Sebastian McKenzie and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View File

@ -54,7 +54,8 @@ function buildLiteralData(formatter, tpl, opts) {
parser: opts.parser,
placeholderWhitelist: new Set(result.names.concat(opts.placeholderWhitelist ? Array.from(opts.placeholderWhitelist) : [])),
placeholderPattern: opts.placeholderPattern,
preserveComments: opts.preserveComments
preserveComments: opts.preserveComments,
syntacticPlaceholders: opts.syntacticPlaceholders
});
} while (metadata.placeholders.some(placeholder => placeholder.isDuplicate && nameSet.has(placeholder.name)));

View File

@ -13,13 +13,15 @@ function merge(a, b) {
const {
placeholderWhitelist = a.placeholderWhitelist,
placeholderPattern = a.placeholderPattern,
preserveComments = a.preserveComments
preserveComments = a.preserveComments,
syntacticPlaceholders = a.syntacticPlaceholders
} = b;
return {
parser: Object.assign({}, a.parser, b.parser),
placeholderWhitelist,
placeholderPattern,
preserveComments
preserveComments,
syntacticPlaceholders
};
}
@ -32,9 +34,10 @@ function validate(opts) {
{
placeholderWhitelist,
placeholderPattern,
preserveComments
preserveComments,
syntacticPlaceholders
} = _ref,
parser = _objectWithoutPropertiesLoose(_ref, ["placeholderWhitelist", "placeholderPattern", "preserveComments"]);
parser = _objectWithoutPropertiesLoose(_ref, ["placeholderWhitelist", "placeholderPattern", "preserveComments", "syntacticPlaceholders"]);
if (placeholderWhitelist != null && !(placeholderWhitelist instanceof Set)) {
throw new Error("'.placeholderWhitelist' must be a Set, null, or undefined");
@ -48,11 +51,20 @@ function validate(opts) {
throw new Error("'.preserveComments' must be a boolean, null, or undefined");
}
if (syntacticPlaceholders != null && typeof syntacticPlaceholders !== "boolean") {
throw new Error("'.syntacticPlaceholders' must be a boolean, null, or undefined");
}
if (syntacticPlaceholders === true && (placeholderWhitelist != null || placeholderPattern != null)) {
throw new Error("'.placeholderWhitelist' and '.placeholderPattern' aren't compatible" + " with '.syntacticPlaceholders: true'");
}
return {
parser,
placeholderWhitelist: placeholderWhitelist || undefined,
placeholderPattern: placeholderPattern == null ? undefined : placeholderPattern,
preserveComments: preserveComments == null ? false : preserveComments
preserveComments: preserveComments == null ? false : preserveComments,
syntacticPlaceholders: syntacticPlaceholders == null ? undefined : syntacticPlaceholders
};
}

View File

@ -43,40 +43,65 @@ function parseAndBuildMetadata(formatter, code, opts) {
const ast = parseWithCodeFrame(code, opts.parser);
const {
placeholderWhitelist,
placeholderPattern = PATTERN,
preserveComments
placeholderPattern,
preserveComments,
syntacticPlaceholders
} = opts;
t().removePropertiesDeep(ast, {
preserveComments
});
formatter.validate(ast);
const placeholders = [];
const placeholderNames = new Set();
t().traverse(ast, placeholderVisitorHandler, {
placeholders,
placeholderNames,
placeholderWhitelist,
placeholderPattern
});
return {
ast,
placeholders,
placeholderNames
const syntactic = {
placeholders: [],
placeholderNames: new Set()
};
const legacy = {
placeholders: [],
placeholderNames: new Set()
};
const isLegacyRef = {
value: undefined
};
t().traverse(ast, placeholderVisitorHandler, {
syntactic,
legacy,
isLegacyRef,
placeholderWhitelist,
placeholderPattern,
syntacticPlaceholders
});
return Object.assign({
ast
}, isLegacyRef.value ? legacy : syntactic);
}
function placeholderVisitorHandler(node, ancestors, state) {
let name;
if (t().isIdentifier(node) || t().isJSXIdentifier(node)) {
if (t().isPlaceholder(node)) {
if (state.syntacticPlaceholders === false) {
throw new Error("%%foo%%-style placeholders can't be used when " + "'.syntacticPlaceholders' is false.");
} else {
name = node.name.name;
state.isLegacyRef.value = false;
}
} else if (state.isLegacyRef.value === false || state.syntacticPlaceholders) {
return;
} else if (t().isIdentifier(node) || t().isJSXIdentifier(node)) {
name = node.name;
state.isLegacyRef.value = true;
} else if (t().isStringLiteral(node)) {
name = node.value;
state.isLegacyRef.value = true;
} else {
return;
}
if ((!state.placeholderPattern || !state.placeholderPattern.test(name)) && (!state.placeholderWhitelist || !state.placeholderWhitelist.has(name))) {
if (!state.isLegacyRef.value && (state.placeholderPattern != null || state.placeholderWhitelist != null)) {
throw new Error("'.placeholderWhitelist' and '.placeholderPattern' aren't compatible" + " with '.syntacticPlaceholders: true'");
}
if (state.isLegacyRef.value && (state.placeholderPattern === false || !(state.placeholderPattern || PATTERN).test(name)) && (!state.placeholderWhitelist || !state.placeholderWhitelist.has(name))) {
return;
}
@ -87,24 +112,32 @@ function placeholderVisitorHandler(node, ancestors, state) {
} = ancestors[ancestors.length - 1];
let type;
if (t().isStringLiteral(node)) {
if (t().isStringLiteral(node) || t().isPlaceholder(node, {
expectedNode: "StringLiteral"
})) {
type = "string";
} else if (t().isNewExpression(parent) && key === "arguments" || t().isCallExpression(parent) && key === "arguments" || t().isFunction(parent) && key === "params") {
type = "param";
} else if (t().isExpressionStatement(parent)) {
} else if (t().isExpressionStatement(parent) && !t().isPlaceholder(node)) {
type = "statement";
ancestors = ancestors.slice(0, -1);
} else if (t().isStatement(node) && t().isPlaceholder(node)) {
type = "statement";
} else {
type = "other";
}
state.placeholders.push({
const {
placeholders,
placeholderNames
} = state.isLegacyRef.value ? state.legacy : state.syntactic;
placeholders.push({
name,
type,
resolve: ast => resolveAncestors(ast, ancestors),
isDuplicate: state.placeholderNames.has(name)
isDuplicate: placeholderNames.has(name)
});
state.placeholderNames.add(name);
placeholderNames.add(name);
}
function resolveAncestors(ast, ancestors) {
@ -139,7 +172,9 @@ function parseWithCodeFrame(code, parserOpts) {
allowReturnOutsideFunction: true,
allowSuperOutsideMethod: true,
sourceType: "module"
}, parserOpts);
}, parserOpts, {
plugins: (parserOpts.plugins || []).concat("placeholders")
});
try {
return (0, _parser().parse)(code, parserOpts);

View File

@ -6,11 +6,12 @@
"bundleDependencies": false,
"dependencies": {
"@babel/code-frame": "^7.0.0",
"@babel/parser": "^7.2.2",
"@babel/types": "^7.2.2"
"@babel/parser": "^7.4.4",
"@babel/types": "^7.4.4"
},
"deprecated": false,
"description": "Generate an AST from a string template.",
"gitHead": "2c88694388831b1e5b88e4bbed6781eb2be1edba",
"homepage": "https://babeljs.io/",
"license": "MIT",
"main": "lib/index.js",
@ -22,5 +23,5 @@
"type": "git",
"url": "https://github.com/babel/babel/tree/master/packages/babel-template"
},
"version": "7.2.2"
"version": "7.4.4"
}

View File

@ -53,7 +53,7 @@ function _call(fns) {
const ret = fn.call(this.state, this, this.state);
if (ret && typeof ret === "object" && typeof ret.then === "function") {
throw new Error(`You appear to be using a plugin with an async traversal visitor, ` + `which your current version of Babel does not support.` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`);
throw new Error(`You appear to be using a plugin with an async traversal visitor, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`);
}
if (ret) {
@ -169,7 +169,7 @@ function _resyncKey() {
}
}
} else {
for (const key in this.container) {
for (const key of Object.keys(this.container)) {
if (this.container[key] === this.node) {
return this.setKey(key);
}

View File

@ -76,7 +76,7 @@ class NodePath {
this.parent = parent;
this.hub = hub;
this.contexts = [];
this.data = {};
this.data = Object.create(null);
this.shouldSkip = false;
this.shouldStop = false;
this.removed = false;
@ -149,7 +149,7 @@ class NodePath {
getData(key, def) {
let val = this.data[key];
if (!val && def) val = this.data[key] = def;
if (val === undefined && def !== undefined) val = this.data[key] = def;
return val;
}
@ -208,7 +208,7 @@ for (const type of t().TYPES) {
};
}
for (const type in virtualTypes) {
for (const type of Object.keys(virtualTypes)) {
if (type[0] === "_") continue;
if (t().TYPES.indexOf(type) < 0) t().TYPES.push(type);
const virtualType = virtualTypes[type];

View File

@ -12,6 +12,7 @@ exports.BinaryExpression = BinaryExpression;
exports.LogicalExpression = LogicalExpression;
exports.ConditionalExpression = ConditionalExpression;
exports.SequenceExpression = SequenceExpression;
exports.ParenthesizedExpression = ParenthesizedExpression;
exports.AssignmentExpression = AssignmentExpression;
exports.UpdateExpression = UpdateExpression;
exports.StringLiteral = StringLiteral;
@ -128,6 +129,10 @@ function SequenceExpression() {
return this.get("expressions").pop().getTypeAnnotation();
}
function ParenthesizedExpression() {
return this.get("expression").getTypeAnnotation();
}
function AssignmentExpression() {
return this.get("right").getTypeAnnotation();
}

View File

@ -54,7 +54,7 @@ class PathHoister {
}
isCompatibleScope(scope) {
for (const key in this.bindings) {
for (const key of Object.keys(this.bindings)) {
const binding = this.bindings[key];
if (!scope.bindingIdentifierEquals(key, binding.identifier)) {
@ -92,7 +92,7 @@ class PathHoister {
}
if (targetScope.path.isProgram() || targetScope.path.isFunction()) {
for (const name in this.bindings) {
for (const name of Object.keys(this.bindings)) {
if (!targetScope.hasOwnBinding(name)) continue;
const binding = this.bindings[name];
@ -154,7 +154,7 @@ class PathHoister {
}
hasOwnParamBindings(scope) {
for (const name in this.bindings) {
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;

View File

@ -20,10 +20,12 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
const ReferencedIdentifier = {
types: ["Identifier", "JSXIdentifier"],
checkPath({
node,
parent
}, opts) {
checkPath(path, opts) {
const {
node,
parent
} = path;
if (!t().isIdentifier(node, opts) && !t().isJSXMemberExpression(parent, opts)) {
if (t().isJSXIdentifier(node, opts)) {
if (t().react.isCompatTag(node.name)) return false;
@ -32,7 +34,7 @@ const ReferencedIdentifier = {
}
}
return t().isReferenced(node, parent);
return t().isReferenced(node, parent, path.parentPath.parent);
}
};
@ -52,11 +54,13 @@ exports.ReferencedMemberExpression = ReferencedMemberExpression;
const BindingIdentifier = {
types: ["Identifier"],
checkPath({
node,
parent
}) {
return t().isIdentifier(node) && t().isBinding(node, parent);
checkPath(path) {
const {
node,
parent
} = path;
const grandparent = path.parentPath.parent;
return t().isIdentifier(node) && t().isBinding(node, parent, grandparent);
}
};

View File

@ -57,7 +57,7 @@ const hoistVariablesVisitor = {
if (path.node.kind !== "var") return;
const bindings = path.getBindingIdentifiers();
for (const key in bindings) {
for (const key of Object.keys(bindings)) {
path.scope.push({
id: bindings[key]
});

View File

@ -152,9 +152,7 @@ const collectorVisitor = {
if (binding) binding.reference(path);
} else if (t().isVariableDeclaration(declar)) {
for (const decl of declar.declarations) {
const ids = t().getBindingIdentifiers(decl);
for (const name in ids) {
for (const name of Object.keys(t().getBindingIdentifiers(decl))) {
const binding = scope.getBinding(name);
if (binding) binding.reference(path);
}
@ -371,7 +369,7 @@ class Scope {
do {
console.log("#", scope.block.type);
for (const name in scope.bindings) {
for (const name of Object.keys(scope.bindings)) {
const binding = scope.bindings[name];
console.log(" -", name, {
constant: binding.constant,
@ -472,7 +470,7 @@ class Scope {
registerConstantViolation(path) {
const ids = path.getBindingIdentifiers();
for (const name in ids) {
for (const name of Object.keys(ids)) {
const binding = this.getBinding(name);
if (binding) binding.reassign(path);
}
@ -492,9 +490,9 @@ class Scope {
}
const parent = this.getProgramParent();
const ids = path.getBindingIdentifiers(true);
const ids = path.getOuterBindingIdentifiers(true);
for (const name in ids) {
for (const name of Object.keys(ids)) {
for (const id of ids[name]) {
const local = this.getOwnBinding(name);
@ -687,7 +685,7 @@ class Scope {
const ids = path.getBindingIdentifiers();
let programParent;
for (const name in ids) {
for (const name of Object.keys(ids)) {
if (path.scope.getBinding(name)) continue;
programParent = programParent || path.scope.getProgramParent();
programParent.addGlobal(ids[name]);
@ -800,7 +798,7 @@ class Scope {
let scope = this;
do {
for (const name in scope.bindings) {
for (const name of Object.keys(scope.bindings)) {
const binding = scope.bindings[name];
if (binding.kind === kind) ids[name] = binding;
}

View File

@ -37,7 +37,7 @@ function explode(visitor) {
if (visitor._exploded) return visitor;
visitor._exploded = true;
for (const nodeType in visitor) {
for (const nodeType of Object.keys(visitor)) {
if (shouldIgnoreKey(nodeType)) continue;
const parts = nodeType.split("|");
if (parts.length === 1) continue;
@ -60,7 +60,7 @@ function explode(visitor) {
if (!wrapper) continue;
const fns = visitor[nodeType];
for (const type in fns) {
for (const type of Object.keys(fns)) {
fns[type] = wrapCheck(wrapper, fns[type]);
}
@ -79,7 +79,7 @@ function explode(visitor) {
}
}
for (const nodeType in visitor) {
for (const nodeType of Object.keys(visitor)) {
if (shouldIgnoreKey(nodeType)) continue;
const fns = visitor[nodeType];
let aliases = t().FLIPPED_ALIAS_KEYS[nodeType];
@ -104,7 +104,7 @@ function explode(visitor) {
}
}
for (const nodeType in visitor) {
for (const nodeType of Object.keys(visitor)) {
if (shouldIgnoreKey(nodeType)) continue;
ensureCallbackArrays(visitor[nodeType]);
}
@ -119,7 +119,7 @@ function verify(visitor) {
throw new Error("You passed `traverse()` a function when it expected a visitor object, " + "are you sure you didn't mean `{ enter: Function }`?");
}
for (const nodeType in visitor) {
for (const nodeType of Object.keys(visitor)) {
if (nodeType === "enter" || nodeType === "exit") {
validateVisitorMethods(nodeType, visitor[nodeType]);
}
@ -133,7 +133,7 @@ function verify(visitor) {
const visitors = visitor[nodeType];
if (typeof visitors === "object") {
for (const visitorKey in visitors) {
for (const visitorKey of Object.keys(visitors)) {
if (visitorKey === "enter" || visitorKey === "exit") {
validateVisitorMethods(`${nodeType}.${visitorKey}`, visitors[visitorKey]);
} else {
@ -164,7 +164,7 @@ function merge(visitors, states = [], wrapper) {
const state = states[i];
explode(visitor);
for (const type in visitor) {
for (const type of Object.keys(visitor)) {
let visitorType = visitor[type];
if (state || wrapper) {
@ -182,7 +182,7 @@ function merge(visitors, states = [], wrapper) {
function wrapWithStateOrWrapper(oldVisitor, state, wrapper) {
const newVisitor = {};
for (const key in oldVisitor) {
for (const key of Object.keys(oldVisitor)) {
let fns = oldVisitor[key];
if (!Array.isArray(fns)) continue;
fns = fns.map(function (fn) {
@ -207,7 +207,7 @@ function wrapWithStateOrWrapper(oldVisitor, state, wrapper) {
}
function ensureEntranceObjects(obj) {
for (const key in obj) {
for (const key of Object.keys(obj)) {
if (shouldIgnoreKey(key)) continue;
const fns = obj[key];
@ -248,7 +248,7 @@ function shouldIgnoreKey(key) {
}
function mergePair(dest, src) {
for (const key in src) {
for (const key of Object.keys(src)) {
dest[key] = [].concat(dest[key] || [], src[key]);
}
}

View File

@ -6,11 +6,11 @@
"bundleDependencies": false,
"dependencies": {
"@babel/code-frame": "^7.0.0",
"@babel/generator": "^7.3.4",
"@babel/generator": "^7.4.4",
"@babel/helper-function-name": "^7.1.0",
"@babel/helper-split-export-declaration": "^7.0.0",
"@babel/parser": "^7.3.4",
"@babel/types": "^7.3.4",
"@babel/helper-split-export-declaration": "^7.4.4",
"@babel/parser": "^7.4.5",
"@babel/types": "^7.4.4",
"debug": "^4.1.0",
"globals": "^11.1.0",
"lodash": "^4.17.11"
@ -20,7 +20,7 @@
"devDependencies": {
"@babel/helper-plugin-test-runner": "^7.0.0"
},
"gitHead": "1f6454cc90fe33e0a32260871212e2f719f35741",
"gitHead": "33ab4f166117e2380de3955a0842985f578b01b8",
"homepage": "https://babeljs.io/",
"license": "MIT",
"main": "lib/index.js",
@ -32,5 +32,5 @@
"type": "git",
"url": "https://github.com/babel/babel/tree/master/packages/babel-traverse"
},
"version": "7.3.4"
"version": "7.4.5"
}

View File

@ -42,6 +42,7 @@ exports.assertObjectProperty = assertObjectProperty;
exports.assertRestElement = assertRestElement;
exports.assertReturnStatement = assertReturnStatement;
exports.assertSequenceExpression = assertSequenceExpression;
exports.assertParenthesizedExpression = assertParenthesizedExpression;
exports.assertSwitchCase = assertSwitchCase;
exports.assertSwitchStatement = assertSwitchStatement;
exports.assertThisExpression = assertThisExpression;
@ -146,7 +147,8 @@ exports.assertJSXFragment = assertJSXFragment;
exports.assertJSXOpeningFragment = assertJSXOpeningFragment;
exports.assertJSXClosingFragment = assertJSXClosingFragment;
exports.assertNoop = assertNoop;
exports.assertParenthesizedExpression = assertParenthesizedExpression;
exports.assertPlaceholder = assertPlaceholder;
exports.assertArgumentPlaceholder = assertArgumentPlaceholder;
exports.assertAwaitExpression = assertAwaitExpression;
exports.assertBindExpression = assertBindExpression;
exports.assertClassProperty = assertClassProperty;
@ -437,6 +439,10 @@ function assertSequenceExpression(node, opts = {}) {
assert("SequenceExpression", node, opts);
}
function assertParenthesizedExpression(node, opts = {}) {
assert("ParenthesizedExpression", node, opts);
}
function assertSwitchCase(node, opts = {}) {
assert("SwitchCase", node, opts);
}
@ -853,8 +859,12 @@ function assertNoop(node, opts = {}) {
assert("Noop", node, opts);
}
function assertParenthesizedExpression(node, opts = {}) {
assert("ParenthesizedExpression", node, opts);
function assertPlaceholder(node, opts = {}) {
assert("Placeholder", node, opts);
}
function assertArgumentPlaceholder(node, opts = {}) {
assert("ArgumentPlaceholder", node, opts);
}
function assertAwaitExpression(node, opts = {}) {

View File

@ -42,7 +42,7 @@ function builder(type, ...args) {
i++;
});
for (const key in node) {
for (const key of Object.keys(node)) {
(0, _validate.default)(node, key, node[key]);
}

View File

@ -42,6 +42,7 @@ exports.objectProperty = exports.ObjectProperty = ObjectProperty;
exports.restElement = exports.RestElement = RestElement;
exports.returnStatement = exports.ReturnStatement = ReturnStatement;
exports.sequenceExpression = exports.SequenceExpression = SequenceExpression;
exports.parenthesizedExpression = exports.ParenthesizedExpression = ParenthesizedExpression;
exports.switchCase = exports.SwitchCase = SwitchCase;
exports.switchStatement = exports.SwitchStatement = SwitchStatement;
exports.thisExpression = exports.ThisExpression = ThisExpression;
@ -146,7 +147,8 @@ exports.jSXFragment = exports.jsxFragment = exports.JSXFragment = JSXFragment;
exports.jSXOpeningFragment = exports.jsxOpeningFragment = exports.JSXOpeningFragment = JSXOpeningFragment;
exports.jSXClosingFragment = exports.jsxClosingFragment = exports.JSXClosingFragment = JSXClosingFragment;
exports.noop = exports.Noop = Noop;
exports.parenthesizedExpression = exports.ParenthesizedExpression = ParenthesizedExpression;
exports.placeholder = exports.Placeholder = Placeholder;
exports.argumentPlaceholder = exports.ArgumentPlaceholder = ArgumentPlaceholder;
exports.awaitExpression = exports.AwaitExpression = AwaitExpression;
exports.bindExpression = exports.BindExpression = BindExpression;
exports.classProperty = exports.ClassProperty = ClassProperty;
@ -389,6 +391,10 @@ function SequenceExpression(...args) {
return (0, _builder.default)("SequenceExpression", ...args);
}
function ParenthesizedExpression(...args) {
return (0, _builder.default)("ParenthesizedExpression", ...args);
}
function SwitchCase(...args) {
return (0, _builder.default)("SwitchCase", ...args);
}
@ -805,8 +811,12 @@ function Noop(...args) {
return (0, _builder.default)("Noop", ...args);
}
function ParenthesizedExpression(...args) {
return (0, _builder.default)("ParenthesizedExpression", ...args);
function Placeholder(...args) {
return (0, _builder.default)("Placeholder", ...args);
}
function ArgumentPlaceholder(...args) {
return (0, _builder.default)("ArgumentPlaceholder", ...args);
}
function AwaitExpression(...args) {

View File

@ -63,7 +63,7 @@ function cloneNode(node, deep = true) {
}
if (has(node, "innerComments")) {
newNode.innerComments = node.innerCmments;
newNode.innerComments = node.innerComments;
}
if (has(node, "trailingComments")) {

View File

@ -32,7 +32,7 @@ function gatherSequenceExpressions(nodes, scope, declars) {
for (const declar of node.declarations) {
const bindings = (0, _getBindingIdentifiers.default)(declar);
for (const key in bindings) {
for (const key of Object.keys(bindings)) {
declars.push({
kind: node.kind,
id: (0, _cloneNode.default)(bindings[key])

View File

@ -85,7 +85,7 @@ function valueToNode(value) {
if ((0, _isPlainObject().default)(value)) {
const props = [];
for (const key in value) {
for (const key of Object.keys(value)) {
let nodeKey;
if ((0, _isValidIdentifier.default)(key)) {

View File

@ -114,7 +114,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
validate: (0, _utils.assertNodeType)("Expression")
},
arguments: {
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Expression", "SpreadElement", "JSXNamespacedName")))
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Expression", "SpreadElement", "JSXNamespacedName", "ArgumentPlaceholder")))
},
optional: {
validate: (0, _utils.assertOneOf)(true, false),
@ -572,6 +572,15 @@ exports.patternLikeCommon = patternLikeCommon;
},
aliases: ["Expression"]
});
(0, _utils.default)("ParenthesizedExpression", {
visitor: ["expression"],
aliases: ["Expression", "ExpressionWrapper"],
fields: {
expression: {
validate: (0, _utils.assertNodeType)("Expression")
}
}
});
(0, _utils.default)("SwitchCase", {
visitor: ["test", "consequent"],
fields: {

View File

@ -6,6 +6,7 @@ var _es = require("./es2015");
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
(0, _utils.default)("ArgumentPlaceholder", {});
(0, _utils.default)("AwaitExpression", {
builder: ["argument"],
visitor: ["argument"],

View File

@ -39,6 +39,24 @@ Object.defineProperty(exports, "DEPRECATED_KEYS", {
return _utils.DEPRECATED_KEYS;
}
});
Object.defineProperty(exports, "PLACEHOLDERS", {
enumerable: true,
get: function () {
return _placeholders.PLACEHOLDERS;
}
});
Object.defineProperty(exports, "PLACEHOLDERS_ALIAS", {
enumerable: true,
get: function () {
return _placeholders.PLACEHOLDERS_ALIAS;
}
});
Object.defineProperty(exports, "PLACEHOLDERS_FLIPPED_ALIAS", {
enumerable: true,
get: function () {
return _placeholders.PLACEHOLDERS_FLIPPED_ALIAS;
}
});
exports.TYPES = void 0;
function _toFastProperties() {
@ -67,6 +85,8 @@ require("./typescript");
var _utils = require("./utils");
var _placeholders = require("./placeholders");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
(0, _toFastProperties().default)(_utils.VISITOR_KEYS);
@ -75,5 +95,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
(0, _toFastProperties().default)(_utils.NODE_FIELDS);
(0, _toFastProperties().default)(_utils.BUILDER_KEYS);
(0, _toFastProperties().default)(_utils.DEPRECATED_KEYS);
(0, _toFastProperties().default)(_placeholders.PLACEHOLDERS_ALIAS);
(0, _toFastProperties().default)(_placeholders.PLACEHOLDERS_FLIPPED_ALIAS);
const TYPES = Object.keys(_utils.VISITOR_KEYS).concat(Object.keys(_utils.FLIPPED_ALIAS_KEYS)).concat(Object.keys(_utils.DEPRECATED_KEYS));
exports.TYPES = TYPES;

View File

@ -2,17 +2,22 @@
var _utils = _interopRequireWildcard(require("./utils"));
var _placeholders = require("./placeholders");
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
(0, _utils.default)("Noop", {
visitor: []
});
(0, _utils.default)("ParenthesizedExpression", {
visitor: ["expression"],
aliases: ["Expression", "ExpressionWrapper"],
(0, _utils.default)("Placeholder", {
visitor: [],
builder: ["expectedNode", "name"],
fields: {
expression: {
validate: (0, _utils.assertNodeType)("Expression")
name: {
validate: (0, _utils.assertNodeType)("Identifier")
},
expectedNode: {
validate: (0, _utils.assertOneOf)(..._placeholders.PLACEHOLDERS)
}
}
});

View File

@ -0,0 +1,33 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.PLACEHOLDERS_FLIPPED_ALIAS = exports.PLACEHOLDERS_ALIAS = exports.PLACEHOLDERS = void 0;
var _utils = require("./utils");
const PLACEHOLDERS = ["Identifier", "StringLiteral", "Expression", "Statement", "Declaration", "BlockStatement", "ClassBody", "Pattern"];
exports.PLACEHOLDERS = PLACEHOLDERS;
const PLACEHOLDERS_ALIAS = {
Declaration: ["Statement"],
Pattern: ["PatternLike", "LVal"]
};
exports.PLACEHOLDERS_ALIAS = PLACEHOLDERS_ALIAS;
for (const type of PLACEHOLDERS) {
const alias = _utils.ALIAS_KEYS[type];
if (alias && alias.length) PLACEHOLDERS_ALIAS[type] = alias;
}
const PLACEHOLDERS_FLIPPED_ALIAS = {};
exports.PLACEHOLDERS_FLIPPED_ALIAS = PLACEHOLDERS_FLIPPED_ALIAS;
Object.keys(PLACEHOLDERS_ALIAS).forEach(type => {
PLACEHOLDERS_ALIAS[type].forEach(alias => {
if (!Object.hasOwnProperty.call(PLACEHOLDERS_FLIPPED_ALIAS, alias)) {
PLACEHOLDERS_FLIPPED_ALIAS[alias] = [];
}
PLACEHOLDERS_FLIPPED_ALIAS[alias].push(type);
});
});

View File

@ -110,7 +110,7 @@ for (const type of tsKeywordTypes) {
});
const fnOrCtr = {
aliases: ["TSType"],
visitor: ["typeParameters", "typeAnnotation"],
visitor: ["typeParameters", "parameters", "typeAnnotation"],
fields: signatureDeclarationCommon
};
(0, _utils.default)("TSFunctionType", fnOrCtr);

View File

@ -192,7 +192,7 @@ function defineType(type, opts = {}) {
fields[key] = fields[key] || {};
}
for (const key in fields) {
for (const key of Object.keys(fields)) {
const field = fields[key];
if (builder.indexOf(key) === -1) {

View File

@ -47,6 +47,7 @@ var _exportNames = {
isLet: true,
isNode: true,
isNodesEquivalent: true,
isPlaceholderType: true,
isReferenced: true,
isScope: true,
isSpecifierDefault: true,
@ -310,6 +311,12 @@ Object.defineProperty(exports, "isNodesEquivalent", {
return _isNodesEquivalent.default;
}
});
Object.defineProperty(exports, "isPlaceholderType", {
enumerable: true,
get: function () {
return _isPlaceholderType.default;
}
});
Object.defineProperty(exports, "isReferenced", {
enumerable: true,
get: function () {
@ -527,6 +534,8 @@ var _isNode = _interopRequireDefault(require("./validators/isNode"));
var _isNodesEquivalent = _interopRequireDefault(require("./validators/isNodesEquivalent"));
var _isPlaceholderType = _interopRequireDefault(require("./validators/isPlaceholderType"));
var _isReferenced = _interopRequireDefault(require("./validators/isReferenced"));
var _isScope = _interopRequireDefault(require("./validators/isScope"));

View File

@ -85,7 +85,7 @@ declare class BabelNodeBreakStatement extends BabelNode {
declare class BabelNodeCallExpression extends BabelNode {
type: "CallExpression";
callee: BabelNodeExpression;
arguments: Array<BabelNodeExpression | BabelNodeSpreadElement | BabelNodeJSXNamespacedName>;
arguments: Array<BabelNodeExpression | BabelNodeSpreadElement | BabelNodeJSXNamespacedName | BabelNodeArgumentPlaceholder>;
optional?: true | false;
typeArguments?: BabelNodeTypeParameterInstantiation;
typeParameters?: BabelNodeTSTypeParameterInstantiation;
@ -237,7 +237,7 @@ declare class BabelNodeMemberExpression extends BabelNode {
declare class BabelNodeNewExpression extends BabelNode {
type: "NewExpression";
callee: BabelNodeExpression;
arguments: Array<BabelNodeExpression | BabelNodeSpreadElement | BabelNodeJSXNamespacedName>;
arguments: Array<BabelNodeExpression | BabelNodeSpreadElement | BabelNodeJSXNamespacedName | BabelNodeArgumentPlaceholder>;
optional?: true | false;
typeArguments?: BabelNodeTypeParameterInstantiation;
typeParameters?: BabelNodeTSTypeParameterInstantiation;
@ -297,6 +297,11 @@ declare class BabelNodeSequenceExpression extends BabelNode {
expressions: Array<BabelNodeExpression>;
}
declare class BabelNodeParenthesizedExpression extends BabelNode {
type: "ParenthesizedExpression";
expression: BabelNodeExpression;
}
declare class BabelNodeSwitchCase extends BabelNode {
type: "SwitchCase";
test?: BabelNodeExpression;
@ -932,9 +937,14 @@ declare class BabelNodeNoop extends BabelNode {
type: "Noop";
}
declare class BabelNodeParenthesizedExpression extends BabelNode {
type: "ParenthesizedExpression";
expression: BabelNodeExpression;
declare class BabelNodePlaceholder extends BabelNode {
type: "Placeholder";
expectedNode: "Identifier" | "StringLiteral" | "Expression" | "Statement" | "Declaration" | "BlockStatement" | "ClassBody" | "Pattern";
name: BabelNodeIdentifier;
}
declare class BabelNodeArgumentPlaceholder extends BabelNode {
type: "ArgumentPlaceholder";
}
declare class BabelNodeAwaitExpression extends BabelNode {
@ -1095,14 +1105,14 @@ declare class BabelNodeTSQualifiedName extends BabelNode {
declare class BabelNodeTSCallSignatureDeclaration extends BabelNode {
type: "TSCallSignatureDeclaration";
typeParameters?: BabelNodeTSTypeParameterDeclaration;
parameters?: Array<BabelNodeIdentifier | BabelNodeRestElement>;
parameters: Array<BabelNodeIdentifier | BabelNodeRestElement>;
typeAnnotation?: BabelNodeTSTypeAnnotation;
}
declare class BabelNodeTSConstructSignatureDeclaration extends BabelNode {
type: "TSConstructSignatureDeclaration";
typeParameters?: BabelNodeTSTypeParameterDeclaration;
parameters?: Array<BabelNodeIdentifier | BabelNodeRestElement>;
parameters: Array<BabelNodeIdentifier | BabelNodeRestElement>;
typeAnnotation?: BabelNodeTSTypeAnnotation;
}
@ -1120,7 +1130,7 @@ declare class BabelNodeTSMethodSignature extends BabelNode {
type: "TSMethodSignature";
key: BabelNodeExpression;
typeParameters?: BabelNodeTSTypeParameterDeclaration;
parameters?: Array<BabelNodeIdentifier | BabelNodeRestElement>;
parameters: Array<BabelNodeIdentifier | BabelNodeRestElement>;
typeAnnotation?: BabelNodeTSTypeAnnotation;
computed?: boolean;
optional?: boolean;
@ -1184,15 +1194,15 @@ declare class BabelNodeTSThisType extends BabelNode {
declare class BabelNodeTSFunctionType extends BabelNode {
type: "TSFunctionType";
typeParameters?: BabelNodeTSTypeParameterDeclaration;
parameters: Array<BabelNodeIdentifier | BabelNodeRestElement>;
typeAnnotation?: BabelNodeTSTypeAnnotation;
parameters?: Array<BabelNodeIdentifier | BabelNodeRestElement>;
}
declare class BabelNodeTSConstructorType extends BabelNode {
type: "TSConstructorType";
typeParameters?: BabelNodeTSTypeParameterDeclaration;
parameters: Array<BabelNodeIdentifier | BabelNodeRestElement>;
typeAnnotation?: BabelNodeTSTypeAnnotation;
parameters?: Array<BabelNodeIdentifier | BabelNodeRestElement>;
}
declare class BabelNodeTSTypeReference extends BabelNode {
@ -1411,7 +1421,7 @@ declare class BabelNodeTSTypeParameter extends BabelNode {
name?: string;
}
type BabelNodeExpression = BabelNodeArrayExpression | BabelNodeAssignmentExpression | BabelNodeBinaryExpression | BabelNodeCallExpression | BabelNodeConditionalExpression | BabelNodeFunctionExpression | BabelNodeIdentifier | BabelNodeStringLiteral | BabelNodeNumericLiteral | BabelNodeNullLiteral | BabelNodeBooleanLiteral | BabelNodeRegExpLiteral | BabelNodeLogicalExpression | BabelNodeMemberExpression | BabelNodeNewExpression | BabelNodeObjectExpression | BabelNodeSequenceExpression | BabelNodeThisExpression | BabelNodeUnaryExpression | BabelNodeUpdateExpression | BabelNodeArrowFunctionExpression | BabelNodeClassExpression | BabelNodeMetaProperty | BabelNodeSuper | BabelNodeTaggedTemplateExpression | BabelNodeTemplateLiteral | BabelNodeYieldExpression | BabelNodeTypeCastExpression | BabelNodeJSXElement | BabelNodeJSXFragment | BabelNodeParenthesizedExpression | BabelNodeAwaitExpression | BabelNodeBindExpression | BabelNodeOptionalMemberExpression | BabelNodePipelinePrimaryTopicReference | BabelNodeOptionalCallExpression | BabelNodeImport | BabelNodeDoExpression | BabelNodeBigIntLiteral | BabelNodeTSAsExpression | BabelNodeTSTypeAssertion | BabelNodeTSNonNullExpression;
type BabelNodeExpression = BabelNodeArrayExpression | BabelNodeAssignmentExpression | BabelNodeBinaryExpression | BabelNodeCallExpression | BabelNodeConditionalExpression | BabelNodeFunctionExpression | BabelNodeIdentifier | BabelNodeStringLiteral | BabelNodeNumericLiteral | BabelNodeNullLiteral | BabelNodeBooleanLiteral | BabelNodeRegExpLiteral | BabelNodeLogicalExpression | BabelNodeMemberExpression | BabelNodeNewExpression | BabelNodeObjectExpression | BabelNodeSequenceExpression | BabelNodeParenthesizedExpression | BabelNodeThisExpression | BabelNodeUnaryExpression | BabelNodeUpdateExpression | BabelNodeArrowFunctionExpression | BabelNodeClassExpression | BabelNodeMetaProperty | BabelNodeSuper | BabelNodeTaggedTemplateExpression | BabelNodeTemplateLiteral | BabelNodeYieldExpression | BabelNodeTypeCastExpression | BabelNodeJSXElement | BabelNodeJSXFragment | BabelNodeAwaitExpression | BabelNodeBindExpression | BabelNodeOptionalMemberExpression | BabelNodePipelinePrimaryTopicReference | BabelNodeOptionalCallExpression | BabelNodeImport | BabelNodeDoExpression | BabelNodeBigIntLiteral | BabelNodeTSAsExpression | BabelNodeTSTypeAssertion | BabelNodeTSNonNullExpression;
type BabelNodeBinary = BabelNodeBinaryExpression | BabelNodeLogicalExpression;
type BabelNodeScopable = BabelNodeBlockStatement | BabelNodeCatchClause | BabelNodeDoWhileStatement | BabelNodeForInStatement | BabelNodeForStatement | BabelNodeFunctionDeclaration | BabelNodeFunctionExpression | BabelNodeProgram | BabelNodeObjectMethod | BabelNodeSwitchStatement | BabelNodeWhileStatement | BabelNodeArrowFunctionExpression | BabelNodeClassDeclaration | BabelNodeClassExpression | BabelNodeForOfStatement | BabelNodeClassMethod | BabelNodeClassPrivateMethod;
type BabelNodeBlockParent = BabelNodeBlockStatement | BabelNodeCatchClause | BabelNodeDoWhileStatement | BabelNodeForInStatement | BabelNodeForStatement | BabelNodeFunctionDeclaration | BabelNodeFunctionExpression | BabelNodeProgram | BabelNodeObjectMethod | BabelNodeSwitchStatement | BabelNodeWhileStatement | BabelNodeArrowFunctionExpression | BabelNodeForOfStatement | BabelNodeClassMethod | BabelNodeClassPrivateMethod;
@ -1422,7 +1432,7 @@ type BabelNodeCompletionStatement = BabelNodeBreakStatement | BabelNodeContinueS
type BabelNodeConditional = BabelNodeConditionalExpression | BabelNodeIfStatement;
type BabelNodeLoop = BabelNodeDoWhileStatement | BabelNodeForInStatement | BabelNodeForStatement | BabelNodeWhileStatement | BabelNodeForOfStatement;
type BabelNodeWhile = BabelNodeDoWhileStatement | BabelNodeWhileStatement;
type BabelNodeExpressionWrapper = BabelNodeExpressionStatement | BabelNodeTypeCastExpression | BabelNodeParenthesizedExpression;
type BabelNodeExpressionWrapper = BabelNodeExpressionStatement | BabelNodeParenthesizedExpression | BabelNodeTypeCastExpression;
type BabelNodeFor = BabelNodeForInStatement | BabelNodeForStatement | BabelNodeForOfStatement;
type BabelNodeForXStatement = BabelNodeForInStatement | BabelNodeForOfStatement;
type BabelNodeFunction = BabelNodeFunctionDeclaration | BabelNodeFunctionExpression | BabelNodeObjectMethod | BabelNodeArrowFunctionExpression | BabelNodeClassMethod | BabelNodeClassPrivateMethod;
@ -1463,7 +1473,7 @@ declare module "@babel/types" {
declare function directiveLiteral(value: string): BabelNodeDirectiveLiteral;
declare function blockStatement(body: Array<BabelNodeStatement>, directives?: Array<BabelNodeDirective>): BabelNodeBlockStatement;
declare function breakStatement(label?: BabelNodeIdentifier): BabelNodeBreakStatement;
declare function callExpression(callee: BabelNodeExpression, _arguments: Array<BabelNodeExpression | BabelNodeSpreadElement | BabelNodeJSXNamespacedName>, optional?: true | false, typeArguments?: BabelNodeTypeParameterInstantiation, typeParameters?: BabelNodeTSTypeParameterInstantiation): BabelNodeCallExpression;
declare function callExpression(callee: BabelNodeExpression, _arguments: Array<BabelNodeExpression | BabelNodeSpreadElement | BabelNodeJSXNamespacedName | BabelNodeArgumentPlaceholder>, optional?: true | false, typeArguments?: BabelNodeTypeParameterInstantiation, typeParameters?: BabelNodeTSTypeParameterInstantiation): BabelNodeCallExpression;
declare function catchClause(param?: BabelNodeIdentifier, body: BabelNodeBlockStatement): BabelNodeCatchClause;
declare function conditionalExpression(test: BabelNodeExpression, consequent: BabelNodeExpression, alternate: BabelNodeExpression): BabelNodeConditionalExpression;
declare function continueStatement(label?: BabelNodeIdentifier): BabelNodeContinueStatement;
@ -1486,7 +1496,7 @@ declare module "@babel/types" {
declare function regExpLiteral(pattern: string, flags?: string): BabelNodeRegExpLiteral;
declare function logicalExpression(operator: "||" | "&&" | "??", left: BabelNodeExpression, right: BabelNodeExpression): BabelNodeLogicalExpression;
declare function memberExpression(object: BabelNodeExpression, property: any, computed?: boolean, optional?: true | false): BabelNodeMemberExpression;
declare function newExpression(callee: BabelNodeExpression, _arguments: Array<BabelNodeExpression | BabelNodeSpreadElement | BabelNodeJSXNamespacedName>, optional?: true | false, typeArguments?: BabelNodeTypeParameterInstantiation, typeParameters?: BabelNodeTSTypeParameterInstantiation): BabelNodeNewExpression;
declare function newExpression(callee: BabelNodeExpression, _arguments: Array<BabelNodeExpression | BabelNodeSpreadElement | BabelNodeJSXNamespacedName | BabelNodeArgumentPlaceholder>, optional?: true | false, typeArguments?: BabelNodeTypeParameterInstantiation, typeParameters?: BabelNodeTSTypeParameterInstantiation): BabelNodeNewExpression;
declare function program(body: Array<BabelNodeStatement>, directives?: Array<BabelNodeDirective>, sourceType?: "script" | "module", interpreter?: BabelNodeInterpreterDirective, sourceFile?: string): BabelNodeProgram;
declare function objectExpression(properties: Array<BabelNodeObjectMethod | BabelNodeObjectProperty | BabelNodeSpreadElement>): BabelNodeObjectExpression;
declare function objectMethod(kind?: "method" | "get" | "set", key: any, params: Array<BabelNodeIdentifier | BabelNodePattern | BabelNodeRestElement | BabelNodeTSParameterProperty>, body: BabelNodeBlockStatement, computed?: boolean, async?: boolean, decorators?: Array<BabelNodeDecorator>, generator?: boolean, returnType?: BabelNodeTypeAnnotation | BabelNodeTSTypeAnnotation | BabelNodeNoop, typeParameters?: BabelNodeTypeParameterDeclaration | BabelNodeTSTypeParameterDeclaration | BabelNodeNoop): BabelNodeObjectMethod;
@ -1494,6 +1504,7 @@ declare module "@babel/types" {
declare function restElement(argument: BabelNodeLVal, decorators?: Array<BabelNodeDecorator>, typeAnnotation?: BabelNodeTypeAnnotation | BabelNodeTSTypeAnnotation | BabelNodeNoop): BabelNodeRestElement;
declare function returnStatement(argument?: BabelNodeExpression): BabelNodeReturnStatement;
declare function sequenceExpression(expressions: Array<BabelNodeExpression>): BabelNodeSequenceExpression;
declare function parenthesizedExpression(expression: BabelNodeExpression): BabelNodeParenthesizedExpression;
declare function switchCase(test?: BabelNodeExpression, consequent: Array<BabelNodeStatement>): BabelNodeSwitchCase;
declare function switchStatement(discriminant: BabelNodeExpression, cases: Array<BabelNodeSwitchCase>): BabelNodeSwitchStatement;
declare function thisExpression(): BabelNodeThisExpression;
@ -1597,7 +1608,8 @@ declare module "@babel/types" {
declare function jsxOpeningFragment(): BabelNodeJSXOpeningFragment;
declare function jsxClosingFragment(): BabelNodeJSXClosingFragment;
declare function noop(): BabelNodeNoop;
declare function parenthesizedExpression(expression: BabelNodeExpression): BabelNodeParenthesizedExpression;
declare function placeholder(expectedNode: "Identifier" | "StringLiteral" | "Expression" | "Statement" | "Declaration" | "BlockStatement" | "ClassBody" | "Pattern", name: BabelNodeIdentifier): BabelNodePlaceholder;
declare function argumentPlaceholder(): BabelNodeArgumentPlaceholder;
declare function awaitExpression(argument: BabelNodeExpression): BabelNodeAwaitExpression;
declare function bindExpression(object: any, callee: any): BabelNodeBindExpression;
declare function classProperty(key: BabelNodeIdentifier | BabelNodeStringLiteral | BabelNodeNumericLiteral | BabelNodeExpression, value?: BabelNodeExpression, typeAnnotation?: BabelNodeTypeAnnotation | BabelNodeTSTypeAnnotation | BabelNodeNoop, decorators?: Array<BabelNodeDecorator>, computed?: boolean, abstract?: boolean, accessibility?: "public" | "private" | "protected", definite?: boolean, optional?: boolean, readonly?: boolean, _static?: boolean): BabelNodeClassProperty;
@ -1618,10 +1630,10 @@ declare module "@babel/types" {
declare function tsDeclareFunction(id?: BabelNodeIdentifier, typeParameters?: BabelNodeTSTypeParameterDeclaration | BabelNodeNoop, params: Array<BabelNodeIdentifier | BabelNodePattern | BabelNodeRestElement | BabelNodeTSParameterProperty>, returnType?: BabelNodeTSTypeAnnotation | BabelNodeNoop, async?: boolean, declare?: boolean, generator?: boolean): BabelNodeTSDeclareFunction;
declare function tsDeclareMethod(decorators?: Array<BabelNodeDecorator>, key: BabelNodeIdentifier | BabelNodeStringLiteral | BabelNodeNumericLiteral | BabelNodeExpression, typeParameters?: BabelNodeTSTypeParameterDeclaration | BabelNodeNoop, params: Array<BabelNodeIdentifier | BabelNodePattern | BabelNodeRestElement | BabelNodeTSParameterProperty>, returnType?: BabelNodeTSTypeAnnotation | BabelNodeNoop, abstract?: boolean, access?: "public" | "private" | "protected", accessibility?: "public" | "private" | "protected", async?: boolean, computed?: boolean, generator?: boolean, kind?: "get" | "set" | "method" | "constructor", optional?: boolean, _static?: boolean): BabelNodeTSDeclareMethod;
declare function tsQualifiedName(left: BabelNodeTSEntityName, right: BabelNodeIdentifier): BabelNodeTSQualifiedName;
declare function tsCallSignatureDeclaration(typeParameters?: BabelNodeTSTypeParameterDeclaration, parameters?: Array<BabelNodeIdentifier | BabelNodeRestElement>, typeAnnotation?: BabelNodeTSTypeAnnotation): BabelNodeTSCallSignatureDeclaration;
declare function tsConstructSignatureDeclaration(typeParameters?: BabelNodeTSTypeParameterDeclaration, parameters?: Array<BabelNodeIdentifier | BabelNodeRestElement>, typeAnnotation?: BabelNodeTSTypeAnnotation): BabelNodeTSConstructSignatureDeclaration;
declare function tsCallSignatureDeclaration(typeParameters?: BabelNodeTSTypeParameterDeclaration, parameters: Array<BabelNodeIdentifier | BabelNodeRestElement>, typeAnnotation?: BabelNodeTSTypeAnnotation): BabelNodeTSCallSignatureDeclaration;
declare function tsConstructSignatureDeclaration(typeParameters?: BabelNodeTSTypeParameterDeclaration, parameters: Array<BabelNodeIdentifier | BabelNodeRestElement>, typeAnnotation?: BabelNodeTSTypeAnnotation): BabelNodeTSConstructSignatureDeclaration;
declare function tsPropertySignature(key: BabelNodeExpression, typeAnnotation?: BabelNodeTSTypeAnnotation, initializer?: BabelNodeExpression, computed?: boolean, optional?: boolean, readonly?: boolean): BabelNodeTSPropertySignature;
declare function tsMethodSignature(key: BabelNodeExpression, typeParameters?: BabelNodeTSTypeParameterDeclaration, parameters?: Array<BabelNodeIdentifier | BabelNodeRestElement>, typeAnnotation?: BabelNodeTSTypeAnnotation, computed?: boolean, optional?: boolean): BabelNodeTSMethodSignature;
declare function tsMethodSignature(key: BabelNodeExpression, typeParameters?: BabelNodeTSTypeParameterDeclaration, parameters: Array<BabelNodeIdentifier | BabelNodeRestElement>, typeAnnotation?: BabelNodeTSTypeAnnotation, computed?: boolean, optional?: boolean): BabelNodeTSMethodSignature;
declare function tsIndexSignature(parameters: Array<BabelNodeIdentifier>, typeAnnotation?: BabelNodeTSTypeAnnotation, readonly?: boolean): BabelNodeTSIndexSignature;
declare function tsAnyKeyword(): BabelNodeTSAnyKeyword;
declare function tsUnknownKeyword(): BabelNodeTSUnknownKeyword;
@ -1635,8 +1647,8 @@ declare module "@babel/types" {
declare function tsNullKeyword(): BabelNodeTSNullKeyword;
declare function tsNeverKeyword(): BabelNodeTSNeverKeyword;
declare function tsThisType(): BabelNodeTSThisType;
declare function tsFunctionType(typeParameters?: BabelNodeTSTypeParameterDeclaration, typeAnnotation?: BabelNodeTSTypeAnnotation, parameters?: Array<BabelNodeIdentifier | BabelNodeRestElement>): BabelNodeTSFunctionType;
declare function tsConstructorType(typeParameters?: BabelNodeTSTypeParameterDeclaration, typeAnnotation?: BabelNodeTSTypeAnnotation, parameters?: Array<BabelNodeIdentifier | BabelNodeRestElement>): BabelNodeTSConstructorType;
declare function tsFunctionType(typeParameters?: BabelNodeTSTypeParameterDeclaration, parameters: Array<BabelNodeIdentifier | BabelNodeRestElement>, typeAnnotation?: BabelNodeTSTypeAnnotation): BabelNodeTSFunctionType;
declare function tsConstructorType(typeParameters?: BabelNodeTSTypeParameterDeclaration, parameters: Array<BabelNodeIdentifier | BabelNodeRestElement>, typeAnnotation?: BabelNodeTSTypeAnnotation): BabelNodeTSConstructorType;
declare function tsTypeReference(typeName: BabelNodeTSEntityName, typeParameters?: BabelNodeTSTypeParameterInstantiation): BabelNodeTSTypeReference;
declare function tsTypePredicate(parameterName: BabelNodeIdentifier | BabelNodeTSThisType, typeAnnotation: BabelNodeTSTypeAnnotation): BabelNodeTSTypePredicate;
declare function tsTypeQuery(exprName: BabelNodeTSEntityName | BabelNodeTSImportType): BabelNodeTSTypeQuery;
@ -1713,6 +1725,7 @@ declare module "@babel/types" {
declare function isRestElement(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeRestElement)
declare function isReturnStatement(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeReturnStatement)
declare function isSequenceExpression(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeSequenceExpression)
declare function isParenthesizedExpression(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeParenthesizedExpression)
declare function isSwitchCase(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeSwitchCase)
declare function isSwitchStatement(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeSwitchStatement)
declare function isThisExpression(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeThisExpression)
@ -1817,7 +1830,8 @@ declare module "@babel/types" {
declare function isJSXOpeningFragment(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeJSXOpeningFragment)
declare function isJSXClosingFragment(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeJSXClosingFragment)
declare function isNoop(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeNoop)
declare function isParenthesizedExpression(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeParenthesizedExpression)
declare function isPlaceholder(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodePlaceholder)
declare function isArgumentPlaceholder(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeArgumentPlaceholder)
declare function isAwaitExpression(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeAwaitExpression)
declare function isBindExpression(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeBindExpression)
declare function isClassProperty(node: ?Object, opts?: ?Object): boolean %checks (node instanceof BabelNodeClassProperty)

View File

@ -62,11 +62,11 @@ function removeTypeDuplicates(nodes) {
types.push(node);
}
for (const type in bases) {
for (const type of Object.keys(bases)) {
types.push(bases[type]);
}
for (const name in generics) {
for (const name of Object.keys(generics)) {
types.push(generics[name]);
}

View File

@ -20,7 +20,7 @@ function inherits(child, parent) {
}
}
for (const key in parent) {
for (const key of Object.keys(parent)) {
if (key[0] === "_" && key !== "__clone") child[key] = parent[key];
}

View File

@ -18,7 +18,7 @@ function removeProperties(node, opts = {}) {
if (node[key] != null) node[key] = undefined;
}
for (const key in node) {
for (const key of Object.keys(node)) {
if (key[0] === "_" && node[key] != null) node[key] = undefined;
}

View File

@ -42,6 +42,7 @@ exports.isObjectProperty = isObjectProperty;
exports.isRestElement = isRestElement;
exports.isReturnStatement = isReturnStatement;
exports.isSequenceExpression = isSequenceExpression;
exports.isParenthesizedExpression = isParenthesizedExpression;
exports.isSwitchCase = isSwitchCase;
exports.isSwitchStatement = isSwitchStatement;
exports.isThisExpression = isThisExpression;
@ -146,7 +147,8 @@ exports.isJSXFragment = isJSXFragment;
exports.isJSXOpeningFragment = isJSXOpeningFragment;
exports.isJSXClosingFragment = isJSXClosingFragment;
exports.isNoop = isNoop;
exports.isParenthesizedExpression = isParenthesizedExpression;
exports.isPlaceholder = isPlaceholder;
exports.isArgumentPlaceholder = isArgumentPlaceholder;
exports.isAwaitExpression = isAwaitExpression;
exports.isBindExpression = isBindExpression;
exports.isClassProperty = isClassProperty;
@ -860,6 +862,21 @@ function isSequenceExpression(node, opts) {
return false;
}
function isParenthesizedExpression(node, opts) {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "ParenthesizedExpression") {
if (typeof opts === "undefined") {
return true;
} else {
return (0, _shallowEqual.default)(node, opts);
}
}
return false;
}
function isSwitchCase(node, opts) {
if (!node) return false;
const nodeType = node.type;
@ -2420,11 +2437,26 @@ function isNoop(node, opts) {
return false;
}
function isParenthesizedExpression(node, opts) {
function isPlaceholder(node, opts) {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "ParenthesizedExpression") {
if (nodeType === "Placeholder") {
if (typeof opts === "undefined") {
return true;
} else {
return (0, _shallowEqual.default)(node, opts);
}
}
return false;
}
function isArgumentPlaceholder(node, opts) {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "ArgumentPlaceholder") {
if (typeof opts === "undefined") {
return true;
} else {
@ -3594,7 +3626,7 @@ function isExpression(node, opts) {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "Expression" || "ArrayExpression" === nodeType || "AssignmentExpression" === nodeType || "BinaryExpression" === nodeType || "CallExpression" === nodeType || "ConditionalExpression" === nodeType || "FunctionExpression" === nodeType || "Identifier" === nodeType || "StringLiteral" === nodeType || "NumericLiteral" === nodeType || "NullLiteral" === nodeType || "BooleanLiteral" === nodeType || "RegExpLiteral" === nodeType || "LogicalExpression" === nodeType || "MemberExpression" === nodeType || "NewExpression" === nodeType || "ObjectExpression" === nodeType || "SequenceExpression" === nodeType || "ThisExpression" === nodeType || "UnaryExpression" === nodeType || "UpdateExpression" === nodeType || "ArrowFunctionExpression" === nodeType || "ClassExpression" === nodeType || "MetaProperty" === nodeType || "Super" === nodeType || "TaggedTemplateExpression" === nodeType || "TemplateLiteral" === nodeType || "YieldExpression" === nodeType || "TypeCastExpression" === nodeType || "JSXElement" === nodeType || "JSXFragment" === nodeType || "ParenthesizedExpression" === nodeType || "AwaitExpression" === nodeType || "BindExpression" === nodeType || "OptionalMemberExpression" === nodeType || "PipelinePrimaryTopicReference" === nodeType || "OptionalCallExpression" === nodeType || "Import" === nodeType || "DoExpression" === nodeType || "BigIntLiteral" === nodeType || "TSAsExpression" === nodeType || "TSTypeAssertion" === nodeType || "TSNonNullExpression" === nodeType) {
if (nodeType === "Expression" || "ArrayExpression" === nodeType || "AssignmentExpression" === nodeType || "BinaryExpression" === nodeType || "CallExpression" === nodeType || "ConditionalExpression" === nodeType || "FunctionExpression" === nodeType || "Identifier" === nodeType || "StringLiteral" === nodeType || "NumericLiteral" === nodeType || "NullLiteral" === nodeType || "BooleanLiteral" === nodeType || "RegExpLiteral" === nodeType || "LogicalExpression" === nodeType || "MemberExpression" === nodeType || "NewExpression" === nodeType || "ObjectExpression" === nodeType || "SequenceExpression" === nodeType || "ParenthesizedExpression" === nodeType || "ThisExpression" === nodeType || "UnaryExpression" === nodeType || "UpdateExpression" === nodeType || "ArrowFunctionExpression" === nodeType || "ClassExpression" === nodeType || "MetaProperty" === nodeType || "Super" === nodeType || "TaggedTemplateExpression" === nodeType || "TemplateLiteral" === nodeType || "YieldExpression" === nodeType || "TypeCastExpression" === nodeType || "JSXElement" === nodeType || "JSXFragment" === nodeType || "AwaitExpression" === nodeType || "BindExpression" === nodeType || "OptionalMemberExpression" === nodeType || "PipelinePrimaryTopicReference" === nodeType || "OptionalCallExpression" === nodeType || "Import" === nodeType || "DoExpression" === nodeType || "BigIntLiteral" === nodeType || "TSAsExpression" === nodeType || "TSTypeAssertion" === nodeType || "TSNonNullExpression" === nodeType || nodeType === "Placeholder" && ("Expression" === node.expectedNode || "Identifier" === node.expectedNode || "StringLiteral" === node.expectedNode)) {
if (typeof opts === "undefined") {
return true;
} else {
@ -3624,7 +3656,7 @@ function isScopable(node, opts) {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "Scopable" || "BlockStatement" === nodeType || "CatchClause" === nodeType || "DoWhileStatement" === nodeType || "ForInStatement" === nodeType || "ForStatement" === nodeType || "FunctionDeclaration" === nodeType || "FunctionExpression" === nodeType || "Program" === nodeType || "ObjectMethod" === nodeType || "SwitchStatement" === nodeType || "WhileStatement" === nodeType || "ArrowFunctionExpression" === nodeType || "ClassDeclaration" === nodeType || "ClassExpression" === nodeType || "ForOfStatement" === nodeType || "ClassMethod" === nodeType || "ClassPrivateMethod" === nodeType) {
if (nodeType === "Scopable" || "BlockStatement" === nodeType || "CatchClause" === nodeType || "DoWhileStatement" === nodeType || "ForInStatement" === nodeType || "ForStatement" === nodeType || "FunctionDeclaration" === nodeType || "FunctionExpression" === nodeType || "Program" === nodeType || "ObjectMethod" === nodeType || "SwitchStatement" === nodeType || "WhileStatement" === nodeType || "ArrowFunctionExpression" === nodeType || "ClassDeclaration" === nodeType || "ClassExpression" === nodeType || "ForOfStatement" === nodeType || "ClassMethod" === nodeType || "ClassPrivateMethod" === nodeType || nodeType === "Placeholder" && "BlockStatement" === node.expectedNode) {
if (typeof opts === "undefined") {
return true;
} else {
@ -3639,7 +3671,7 @@ function isBlockParent(node, opts) {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "BlockParent" || "BlockStatement" === nodeType || "CatchClause" === nodeType || "DoWhileStatement" === nodeType || "ForInStatement" === nodeType || "ForStatement" === nodeType || "FunctionDeclaration" === nodeType || "FunctionExpression" === nodeType || "Program" === nodeType || "ObjectMethod" === nodeType || "SwitchStatement" === nodeType || "WhileStatement" === nodeType || "ArrowFunctionExpression" === nodeType || "ForOfStatement" === nodeType || "ClassMethod" === nodeType || "ClassPrivateMethod" === nodeType) {
if (nodeType === "BlockParent" || "BlockStatement" === nodeType || "CatchClause" === nodeType || "DoWhileStatement" === nodeType || "ForInStatement" === nodeType || "ForStatement" === nodeType || "FunctionDeclaration" === nodeType || "FunctionExpression" === nodeType || "Program" === nodeType || "ObjectMethod" === nodeType || "SwitchStatement" === nodeType || "WhileStatement" === nodeType || "ArrowFunctionExpression" === nodeType || "ForOfStatement" === nodeType || "ClassMethod" === nodeType || "ClassPrivateMethod" === nodeType || nodeType === "Placeholder" && "BlockStatement" === node.expectedNode) {
if (typeof opts === "undefined") {
return true;
} else {
@ -3654,7 +3686,7 @@ function isBlock(node, opts) {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "Block" || "BlockStatement" === nodeType || "Program" === nodeType) {
if (nodeType === "Block" || "BlockStatement" === nodeType || "Program" === nodeType || nodeType === "Placeholder" && "BlockStatement" === node.expectedNode) {
if (typeof opts === "undefined") {
return true;
} else {
@ -3669,7 +3701,7 @@ function isStatement(node, opts) {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "Statement" || "BlockStatement" === nodeType || "BreakStatement" === nodeType || "ContinueStatement" === nodeType || "DebuggerStatement" === nodeType || "DoWhileStatement" === nodeType || "EmptyStatement" === nodeType || "ExpressionStatement" === nodeType || "ForInStatement" === nodeType || "ForStatement" === nodeType || "FunctionDeclaration" === nodeType || "IfStatement" === nodeType || "LabeledStatement" === nodeType || "ReturnStatement" === nodeType || "SwitchStatement" === nodeType || "ThrowStatement" === nodeType || "TryStatement" === nodeType || "VariableDeclaration" === nodeType || "WhileStatement" === nodeType || "WithStatement" === nodeType || "ClassDeclaration" === nodeType || "ExportAllDeclaration" === nodeType || "ExportDefaultDeclaration" === nodeType || "ExportNamedDeclaration" === nodeType || "ForOfStatement" === nodeType || "ImportDeclaration" === nodeType || "DeclareClass" === nodeType || "DeclareFunction" === nodeType || "DeclareInterface" === nodeType || "DeclareModule" === nodeType || "DeclareModuleExports" === nodeType || "DeclareTypeAlias" === nodeType || "DeclareOpaqueType" === nodeType || "DeclareVariable" === nodeType || "DeclareExportDeclaration" === nodeType || "DeclareExportAllDeclaration" === nodeType || "InterfaceDeclaration" === nodeType || "OpaqueType" === nodeType || "TypeAlias" === nodeType || "TSDeclareFunction" === nodeType || "TSInterfaceDeclaration" === nodeType || "TSTypeAliasDeclaration" === nodeType || "TSEnumDeclaration" === nodeType || "TSModuleDeclaration" === nodeType || "TSImportEqualsDeclaration" === nodeType || "TSExportAssignment" === nodeType || "TSNamespaceExportDeclaration" === nodeType) {
if (nodeType === "Statement" || "BlockStatement" === nodeType || "BreakStatement" === nodeType || "ContinueStatement" === nodeType || "DebuggerStatement" === nodeType || "DoWhileStatement" === nodeType || "EmptyStatement" === nodeType || "ExpressionStatement" === nodeType || "ForInStatement" === nodeType || "ForStatement" === nodeType || "FunctionDeclaration" === nodeType || "IfStatement" === nodeType || "LabeledStatement" === nodeType || "ReturnStatement" === nodeType || "SwitchStatement" === nodeType || "ThrowStatement" === nodeType || "TryStatement" === nodeType || "VariableDeclaration" === nodeType || "WhileStatement" === nodeType || "WithStatement" === nodeType || "ClassDeclaration" === nodeType || "ExportAllDeclaration" === nodeType || "ExportDefaultDeclaration" === nodeType || "ExportNamedDeclaration" === nodeType || "ForOfStatement" === nodeType || "ImportDeclaration" === nodeType || "DeclareClass" === nodeType || "DeclareFunction" === nodeType || "DeclareInterface" === nodeType || "DeclareModule" === nodeType || "DeclareModuleExports" === nodeType || "DeclareTypeAlias" === nodeType || "DeclareOpaqueType" === nodeType || "DeclareVariable" === nodeType || "DeclareExportDeclaration" === nodeType || "DeclareExportAllDeclaration" === nodeType || "InterfaceDeclaration" === nodeType || "OpaqueType" === nodeType || "TypeAlias" === nodeType || "TSDeclareFunction" === nodeType || "TSInterfaceDeclaration" === nodeType || "TSTypeAliasDeclaration" === nodeType || "TSEnumDeclaration" === nodeType || "TSModuleDeclaration" === nodeType || "TSImportEqualsDeclaration" === nodeType || "TSExportAssignment" === nodeType || "TSNamespaceExportDeclaration" === nodeType || nodeType === "Placeholder" && ("Statement" === node.expectedNode || "Declaration" === node.expectedNode || "BlockStatement" === node.expectedNode)) {
if (typeof opts === "undefined") {
return true;
} else {
@ -3759,7 +3791,7 @@ function isExpressionWrapper(node, opts) {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "ExpressionWrapper" || "ExpressionStatement" === nodeType || "TypeCastExpression" === nodeType || "ParenthesizedExpression" === nodeType) {
if (nodeType === "ExpressionWrapper" || "ExpressionStatement" === nodeType || "ParenthesizedExpression" === nodeType || "TypeCastExpression" === nodeType) {
if (typeof opts === "undefined") {
return true;
} else {
@ -3834,7 +3866,7 @@ function isPureish(node, opts) {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "Pureish" || "FunctionDeclaration" === nodeType || "FunctionExpression" === nodeType || "StringLiteral" === nodeType || "NumericLiteral" === nodeType || "NullLiteral" === nodeType || "BooleanLiteral" === nodeType || "ArrowFunctionExpression" === nodeType || "ClassDeclaration" === nodeType || "ClassExpression" === nodeType || "BigIntLiteral" === nodeType) {
if (nodeType === "Pureish" || "FunctionDeclaration" === nodeType || "FunctionExpression" === nodeType || "StringLiteral" === nodeType || "NumericLiteral" === nodeType || "NullLiteral" === nodeType || "BooleanLiteral" === nodeType || "ArrowFunctionExpression" === nodeType || "ClassDeclaration" === nodeType || "ClassExpression" === nodeType || "BigIntLiteral" === nodeType || nodeType === "Placeholder" && "StringLiteral" === node.expectedNode) {
if (typeof opts === "undefined") {
return true;
} else {
@ -3849,7 +3881,7 @@ function isDeclaration(node, opts) {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "Declaration" || "FunctionDeclaration" === nodeType || "VariableDeclaration" === nodeType || "ClassDeclaration" === nodeType || "ExportAllDeclaration" === nodeType || "ExportDefaultDeclaration" === nodeType || "ExportNamedDeclaration" === nodeType || "ImportDeclaration" === nodeType || "DeclareClass" === nodeType || "DeclareFunction" === nodeType || "DeclareInterface" === nodeType || "DeclareModule" === nodeType || "DeclareModuleExports" === nodeType || "DeclareTypeAlias" === nodeType || "DeclareOpaqueType" === nodeType || "DeclareVariable" === nodeType || "DeclareExportDeclaration" === nodeType || "DeclareExportAllDeclaration" === nodeType || "InterfaceDeclaration" === nodeType || "OpaqueType" === nodeType || "TypeAlias" === nodeType || "TSDeclareFunction" === nodeType || "TSInterfaceDeclaration" === nodeType || "TSTypeAliasDeclaration" === nodeType || "TSEnumDeclaration" === nodeType || "TSModuleDeclaration" === nodeType) {
if (nodeType === "Declaration" || "FunctionDeclaration" === nodeType || "VariableDeclaration" === nodeType || "ClassDeclaration" === nodeType || "ExportAllDeclaration" === nodeType || "ExportDefaultDeclaration" === nodeType || "ExportNamedDeclaration" === nodeType || "ImportDeclaration" === nodeType || "DeclareClass" === nodeType || "DeclareFunction" === nodeType || "DeclareInterface" === nodeType || "DeclareModule" === nodeType || "DeclareModuleExports" === nodeType || "DeclareTypeAlias" === nodeType || "DeclareOpaqueType" === nodeType || "DeclareVariable" === nodeType || "DeclareExportDeclaration" === nodeType || "DeclareExportAllDeclaration" === nodeType || "InterfaceDeclaration" === nodeType || "OpaqueType" === nodeType || "TypeAlias" === nodeType || "TSDeclareFunction" === nodeType || "TSInterfaceDeclaration" === nodeType || "TSTypeAliasDeclaration" === nodeType || "TSEnumDeclaration" === nodeType || "TSModuleDeclaration" === nodeType || nodeType === "Placeholder" && "Declaration" === node.expectedNode) {
if (typeof opts === "undefined") {
return true;
} else {
@ -3864,7 +3896,7 @@ function isPatternLike(node, opts) {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "PatternLike" || "Identifier" === nodeType || "RestElement" === nodeType || "AssignmentPattern" === nodeType || "ArrayPattern" === nodeType || "ObjectPattern" === nodeType) {
if (nodeType === "PatternLike" || "Identifier" === nodeType || "RestElement" === nodeType || "AssignmentPattern" === nodeType || "ArrayPattern" === nodeType || "ObjectPattern" === nodeType || nodeType === "Placeholder" && ("Pattern" === node.expectedNode || "Identifier" === node.expectedNode)) {
if (typeof opts === "undefined") {
return true;
} else {
@ -3879,7 +3911,7 @@ function isLVal(node, opts) {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "LVal" || "Identifier" === nodeType || "MemberExpression" === nodeType || "RestElement" === nodeType || "AssignmentPattern" === nodeType || "ArrayPattern" === nodeType || "ObjectPattern" === nodeType || "TSParameterProperty" === nodeType) {
if (nodeType === "LVal" || "Identifier" === nodeType || "MemberExpression" === nodeType || "RestElement" === nodeType || "AssignmentPattern" === nodeType || "ArrayPattern" === nodeType || "ObjectPattern" === nodeType || "TSParameterProperty" === nodeType || nodeType === "Placeholder" && ("Pattern" === node.expectedNode || "Identifier" === node.expectedNode)) {
if (typeof opts === "undefined") {
return true;
} else {
@ -3894,7 +3926,7 @@ function isTSEntityName(node, opts) {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "TSEntityName" || "Identifier" === nodeType || "TSQualifiedName" === nodeType) {
if (nodeType === "TSEntityName" || "Identifier" === nodeType || "TSQualifiedName" === nodeType || nodeType === "Placeholder" && "Identifier" === node.expectedNode) {
if (typeof opts === "undefined") {
return true;
} else {
@ -3909,7 +3941,7 @@ function isLiteral(node, opts) {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "Literal" || "StringLiteral" === nodeType || "NumericLiteral" === nodeType || "NullLiteral" === nodeType || "BooleanLiteral" === nodeType || "RegExpLiteral" === nodeType || "TemplateLiteral" === nodeType || "BigIntLiteral" === nodeType) {
if (nodeType === "Literal" || "StringLiteral" === nodeType || "NumericLiteral" === nodeType || "NullLiteral" === nodeType || "BooleanLiteral" === nodeType || "RegExpLiteral" === nodeType || "TemplateLiteral" === nodeType || "BigIntLiteral" === nodeType || nodeType === "Placeholder" && "StringLiteral" === node.expectedNode) {
if (typeof opts === "undefined") {
return true;
} else {
@ -3924,7 +3956,7 @@ function isImmutable(node, opts) {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "Immutable" || "StringLiteral" === nodeType || "NumericLiteral" === nodeType || "NullLiteral" === nodeType || "BooleanLiteral" === nodeType || "JSXAttribute" === nodeType || "JSXClosingElement" === nodeType || "JSXElement" === nodeType || "JSXExpressionContainer" === nodeType || "JSXSpreadChild" === nodeType || "JSXOpeningElement" === nodeType || "JSXText" === nodeType || "JSXFragment" === nodeType || "JSXOpeningFragment" === nodeType || "JSXClosingFragment" === nodeType || "BigIntLiteral" === nodeType) {
if (nodeType === "Immutable" || "StringLiteral" === nodeType || "NumericLiteral" === nodeType || "NullLiteral" === nodeType || "BooleanLiteral" === nodeType || "JSXAttribute" === nodeType || "JSXClosingElement" === nodeType || "JSXElement" === nodeType || "JSXExpressionContainer" === nodeType || "JSXSpreadChild" === nodeType || "JSXOpeningElement" === nodeType || "JSXText" === nodeType || "JSXFragment" === nodeType || "JSXOpeningFragment" === nodeType || "JSXClosingFragment" === nodeType || "BigIntLiteral" === nodeType || nodeType === "Placeholder" && "StringLiteral" === node.expectedNode) {
if (typeof opts === "undefined") {
return true;
} else {
@ -4014,7 +4046,7 @@ function isPattern(node, opts) {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "Pattern" || "AssignmentPattern" === nodeType || "ArrayPattern" === nodeType || "ObjectPattern" === nodeType) {
if (nodeType === "Pattern" || "AssignmentPattern" === nodeType || "ArrayPattern" === nodeType || "ObjectPattern" === nodeType || nodeType === "Placeholder" && "Pattern" === node.expectedNode) {
if (typeof opts === "undefined") {
return true;
} else {

View File

@ -9,12 +9,23 @@ var _shallowEqual = _interopRequireDefault(require("../utils/shallowEqual"));
var _isType = _interopRequireDefault(require("./isType"));
var _isPlaceholderType = _interopRequireDefault(require("./isPlaceholderType"));
var _definitions = require("../definitions");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function is(type, node, opts) {
if (!node) return false;
const matches = (0, _isType.default)(node.type, type);
if (!matches) return false;
if (!matches) {
if (!opts && node.type === "Placeholder" && type in _definitions.FLIPPED_ALIAS_KEYS) {
return (0, _isPlaceholderType.default)(node.expectedNode, type);
}
return false;
}
if (typeof opts === "undefined") {
return true;

View File

@ -9,7 +9,11 @@ var _getBindingIdentifiers = _interopRequireDefault(require("../retrievers/getBi
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function isBinding(node, parent) {
function isBinding(node, parent, grandparent) {
if (grandparent && node.type === "Identifier" && parent.type === "ObjectProperty" && grandparent.type === "ObjectExpression") {
return false;
}
const keys = _getBindingIdentifiers.default.keys[parent.type];
if (keys) {

View File

@ -24,6 +24,12 @@ function isNodesEquivalent(a, b) {
return false;
}
if (a[field] == null && b[field] == null) {
continue;
} else if (a[field] == null || b[field] == null) {
return false;
}
if (Array.isArray(a[field])) {
if (!Array.isArray(b[field])) {
return false;
@ -43,7 +49,7 @@ function isNodesEquivalent(a, b) {
}
if (typeof a[field] === "object" && (!visitorKeys || !visitorKeys.includes(field))) {
for (const key in a[field]) {
for (const key of Object.keys(a[field])) {
if (a[field][key] !== b[field][key]) {
return false;
}

View File

@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isPlaceholderType;
var _definitions = require("../definitions");
function isPlaceholderType(placeholderType, targetType) {
if (placeholderType === targetType) return true;
const aliases = _definitions.PLACEHOLDERS_ALIAS[placeholderType];
if (aliases) {
for (const alias of aliases) {
if (targetType === alias) return true;
}
}
return false;
}

View File

@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
});
exports.default = isReferenced;
function isReferenced(node, parent) {
function isReferenced(node, parent, grandparent) {
switch (parent.type) {
case "MemberExpression":
case "JSXMemberExpression":
@ -29,6 +29,9 @@ function isReferenced(node, parent) {
return parent.local === node;
case "PrivateName":
return false;
case "ObjectProperty":
case "ClassProperty":
case "ClassPrivateProperty":
@ -39,7 +42,11 @@ function isReferenced(node, parent) {
return !!parent.computed;
}
return parent.value === node;
if (parent.value === node) {
return !grandparent || grandparent.type !== "ObjectPattern";
}
return true;
case "ClassDeclaration":
case "ClassExpression":
@ -89,6 +96,16 @@ function isReferenced(node, parent) {
case "ObjectTypeProperty":
return parent.key !== node;
case "TSEnumMember":
return parent.id !== node;
case "TSPropertySignature":
if (parent.key === node) {
return !!parent.computed;
}
return true;
}
return true;

View File

@ -12,10 +12,10 @@
"deprecated": false,
"description": "Babel Types is a Lodash-esque utility library for AST nodes",
"devDependencies": {
"@babel/generator": "^7.3.4",
"@babel/parser": "^7.3.4"
"@babel/generator": "^7.4.4",
"@babel/parser": "^7.4.4"
},
"gitHead": "1f6454cc90fe33e0a32260871212e2f719f35741",
"gitHead": "2c88694388831b1e5b88e4bbed6781eb2be1edba",
"homepage": "https://babeljs.io/",
"license": "MIT",
"main": "lib/index.js",
@ -25,5 +25,5 @@
"url": "https://github.com/babel/babel/tree/master/packages/babel-types"
},
"types": "lib/index.d.ts",
"version": "7.3.4"
"version": "7.4.4"
}

View File

@ -1,39 +1,29 @@
"use strict";
const fs = require("fs");
const path = require("path");
const chalk = require("chalk");
const generateBuilders = require("./generators/generateBuilders");
const generateValidators = require("./generators/generateValidators");
const generateAsserts = require("./generators/generateAsserts");
const generateConstants = require("./generators/generateConstants");
const format = require("./utils/formatCode");
const format = require("../../../scripts/utils/formatCode");
const writeFile = require("../../../scripts/utils/writeFileAndMkDir");
const baseDir = path.join(__dirname, "../src");
function writeFile(content, location) {
const file = path.join(baseDir, location);
try {
fs.mkdirSync(path.dirname(file));
} catch (error) {
if (error.code !== "EEXIST") {
throw error;
}
}
fs.writeFileSync(file, format(content, file));
}
console.log("Generating @babel/types dynamic functions");
writeFile(generateBuilders(), "builders/generated/index.js");
const buildersFile = path.join(baseDir, "builders/generated/index.js");
writeFile(buildersFile, format(generateBuilders(), buildersFile));
console.log(` ${chalk.green("✔")} Generated builders`);
writeFile(generateValidators(), "validators/generated/index.js");
const validatorsFile = path.join(baseDir, "validators/generated/index.js");
writeFile(validatorsFile, format(generateValidators(), validatorsFile));
console.log(` ${chalk.green("✔")} Generated validators`);
writeFile(generateAsserts(), "asserts/generated/index.js");
const assertsFile = path.join(baseDir, "asserts/generated/index.js");
writeFile(assertsFile, format(generateAsserts(), assertsFile));
console.log(` ${chalk.green("✔")} Generated asserts`);
writeFile(generateConstants(), "constants/generated/index.js");
const constantsFile = path.join(baseDir, "constants/generated/index.js");
writeFile(constantsFile, format(generateConstants(), constantsFile));
console.log(` ${chalk.green("✔")} Generated constants`);

View File

@ -1,14 +1,37 @@
"use strict";
const definitions = require("../../lib/definitions");
const has = Function.call.bind(Object.prototype.hasOwnProperty);
function joinComparisons(leftArr, right) {
return (
leftArr.map(JSON.stringify).join(` === ${right} || `) + ` === ${right}`
);
}
function addIsHelper(type, aliasKeys, deprecated) {
const targetType = JSON.stringify(type);
let aliasSource = "";
if (aliasKeys) {
aliasSource =
" || " +
aliasKeys.map(JSON.stringify).join(" === nodeType || ") +
" === nodeType";
aliasSource = " || " + joinComparisons(aliasKeys, "nodeType");
}
let placeholderSource = "";
const placeholderTypes = [];
if (
definitions.PLACEHOLDERS.includes(type) &&
has(definitions.FLIPPED_ALIAS_KEYS, type)
) {
placeholderTypes.push(type);
}
if (has(definitions.PLACEHOLDERS_FLIPPED_ALIAS, type)) {
placeholderTypes.push(...definitions.PLACEHOLDERS_FLIPPED_ALIAS[type]);
}
if (placeholderTypes.length > 0) {
placeholderSource =
' || nodeType === "Placeholder" && (' +
joinComparisons(placeholderTypes, "node.expectedNode") +
")";
}
return `export function is${type}(node: ?Object, opts?: Object): boolean {
@ -16,7 +39,7 @@ function addIsHelper(type, aliasKeys, deprecated) {
if (!node) return false;
const nodeType = node.type;
if (nodeType === ${targetType}${aliasSource}) {
if (nodeType === ${targetType}${aliasSource}${placeholderSource}) {
if (typeof opts === "undefined") {
return true;
} else {

View File

@ -1,11 +0,0 @@
"use strict";
const prettier = require("prettier");
module.exports = function formatCode(code, filename) {
filename = filename || __filename;
const prettierConfig = prettier.resolveConfig.sync(filename);
prettierConfig.filepath = filename;
prettierConfig.parser = "babylon";
return prettier.format(code, prettierConfig);
};

View File

@ -21,6 +21,7 @@
"Float32Array": false,
"Float64Array": false,
"Function": false,
"globalThis": false,
"hasOwnProperty": false,
"Infinity": false,
"Int16Array": false,

View File

@ -41,7 +41,7 @@
"scripts": {
"test": "xo && ava"
},
"version": "11.11.0",
"version": "11.12.0",
"xo": {
"ignores": [
"get-browser-globals.js"