refactor: reorganize babel types definitions structure (#11843)

* refactor: reorganize babel types definitions structure

* chore: update generated artifacts
This commit is contained in:
Huáng Jùnliàng 2020-07-15 17:34:31 -04:00 committed by GitHub
parent e12caf4f69
commit 02f30af59c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 997 additions and 1007 deletions

View File

@ -305,6 +305,33 @@ export function assertTemplateLiteral(node: Object, opts?: Object = {}): void {
export function assertYieldExpression(node: Object, opts?: Object = {}): void {
assert("YieldExpression", node, opts);
}
export function assertAwaitExpression(node: Object, opts?: Object = {}): void {
assert("AwaitExpression", node, opts);
}
export function assertImport(node: Object, opts?: Object = {}): void {
assert("Import", node, opts);
}
export function assertBigIntLiteral(node: Object, opts?: Object = {}): void {
assert("BigIntLiteral", node, opts);
}
export function assertExportNamespaceSpecifier(
node: Object,
opts?: Object = {},
): void {
assert("ExportNamespaceSpecifier", node, opts);
}
export function assertOptionalMemberExpression(
node: Object,
opts?: Object = {},
): void {
assert("OptionalMemberExpression", node, opts);
}
export function assertOptionalCallExpression(
node: Object,
opts?: Object = {},
): void {
assert("OptionalCallExpression", node, opts);
}
export function assertAnyTypeAnnotation(
node: Object,
opts?: Object = {},
@ -713,21 +740,12 @@ export function assertArgumentPlaceholder(
): void {
assert("ArgumentPlaceholder", node, opts);
}
export function assertAwaitExpression(node: Object, opts?: Object = {}): void {
assert("AwaitExpression", node, opts);
}
export function assertBindExpression(node: Object, opts?: Object = {}): void {
assert("BindExpression", node, opts);
}
export function assertClassProperty(node: Object, opts?: Object = {}): void {
assert("ClassProperty", node, opts);
}
export function assertOptionalMemberExpression(
node: Object,
opts?: Object = {},
): void {
assert("OptionalMemberExpression", node, opts);
}
export function assertPipelineTopicExpression(
node: Object,
opts?: Object = {},
@ -746,12 +764,6 @@ export function assertPipelinePrimaryTopicReference(
): void {
assert("PipelinePrimaryTopicReference", node, opts);
}
export function assertOptionalCallExpression(
node: Object,
opts?: Object = {},
): void {
assert("OptionalCallExpression", node, opts);
}
export function assertClassPrivateProperty(
node: Object,
opts?: Object = {},
@ -764,9 +776,6 @@ export function assertClassPrivateMethod(
): void {
assert("ClassPrivateMethod", node, opts);
}
export function assertImport(node: Object, opts?: Object = {}): void {
assert("Import", node, opts);
}
export function assertImportAttribute(node: Object, opts?: Object = {}): void {
assert("ImportAttribute", node, opts);
}
@ -782,18 +791,9 @@ export function assertExportDefaultSpecifier(
): void {
assert("ExportDefaultSpecifier", node, opts);
}
export function assertExportNamespaceSpecifier(
node: Object,
opts?: Object = {},
): void {
assert("ExportNamespaceSpecifier", node, opts);
}
export function assertPrivateName(node: Object, opts?: Object = {}): void {
assert("PrivateName", node, opts);
}
export function assertBigIntLiteral(node: Object, opts?: Object = {}): void {
assert("BigIntLiteral", node, opts);
}
export function assertRecordExpression(node: Object, opts?: Object = {}): void {
assert("RecordExpression", node, opts);
}

View File

@ -306,6 +306,31 @@ export function yieldExpression(...args: Array<any>): Object {
return builder("YieldExpression", ...args);
}
export { yieldExpression as YieldExpression };
export function awaitExpression(...args: Array<any>): Object {
return builder("AwaitExpression", ...args);
}
export { awaitExpression as AwaitExpression };
function _import(...args: Array<any>): Object {
return builder("Import", ...args);
}
export { _import as Import };
export { _import as import };
export function bigIntLiteral(...args: Array<any>): Object {
return builder("BigIntLiteral", ...args);
}
export { bigIntLiteral as BigIntLiteral };
export function exportNamespaceSpecifier(...args: Array<any>): Object {
return builder("ExportNamespaceSpecifier", ...args);
}
export { exportNamespaceSpecifier as ExportNamespaceSpecifier };
export function optionalMemberExpression(...args: Array<any>): Object {
return builder("OptionalMemberExpression", ...args);
}
export { optionalMemberExpression as OptionalMemberExpression };
export function optionalCallExpression(...args: Array<any>): Object {
return builder("OptionalCallExpression", ...args);
}
export { optionalCallExpression as OptionalCallExpression };
export function anyTypeAnnotation(...args: Array<any>): Object {
return builder("AnyTypeAnnotation", ...args);
}
@ -649,10 +674,6 @@ export function argumentPlaceholder(...args: Array<any>): Object {
return builder("ArgumentPlaceholder", ...args);
}
export { argumentPlaceholder as ArgumentPlaceholder };
export function awaitExpression(...args: Array<any>): Object {
return builder("AwaitExpression", ...args);
}
export { awaitExpression as AwaitExpression };
export function bindExpression(...args: Array<any>): Object {
return builder("BindExpression", ...args);
}
@ -661,10 +682,6 @@ export function classProperty(...args: Array<any>): Object {
return builder("ClassProperty", ...args);
}
export { classProperty as ClassProperty };
export function optionalMemberExpression(...args: Array<any>): Object {
return builder("OptionalMemberExpression", ...args);
}
export { optionalMemberExpression as OptionalMemberExpression };
export function pipelineTopicExpression(...args: Array<any>): Object {
return builder("PipelineTopicExpression", ...args);
}
@ -677,10 +694,6 @@ export function pipelinePrimaryTopicReference(...args: Array<any>): Object {
return builder("PipelinePrimaryTopicReference", ...args);
}
export { pipelinePrimaryTopicReference as PipelinePrimaryTopicReference };
export function optionalCallExpression(...args: Array<any>): Object {
return builder("OptionalCallExpression", ...args);
}
export { optionalCallExpression as OptionalCallExpression };
export function classPrivateProperty(...args: Array<any>): Object {
return builder("ClassPrivateProperty", ...args);
}
@ -689,11 +702,6 @@ export function classPrivateMethod(...args: Array<any>): Object {
return builder("ClassPrivateMethod", ...args);
}
export { classPrivateMethod as ClassPrivateMethod };
function _import(...args: Array<any>): Object {
return builder("Import", ...args);
}
export { _import as Import };
export { _import as import };
export function importAttribute(...args: Array<any>): Object {
return builder("ImportAttribute", ...args);
}
@ -710,18 +718,10 @@ export function exportDefaultSpecifier(...args: Array<any>): Object {
return builder("ExportDefaultSpecifier", ...args);
}
export { exportDefaultSpecifier as ExportDefaultSpecifier };
export function exportNamespaceSpecifier(...args: Array<any>): Object {
return builder("ExportNamespaceSpecifier", ...args);
}
export { exportNamespaceSpecifier as ExportNamespaceSpecifier };
export function privateName(...args: Array<any>): Object {
return builder("PrivateName", ...args);
}
export { privateName as PrivateName };
export function bigIntLiteral(...args: Array<any>): Object {
return builder("BigIntLiteral", ...args);
}
export { bigIntLiteral as BigIntLiteral };
export function recordExpression(...args: Array<any>): Object {
return builder("RecordExpression", ...args);
}

View File

@ -13,12 +13,15 @@ import {
} from "../constants";
import defineType, {
assertShape,
assertOptionalChainStart,
assertValueType,
assertNodeType,
assertNodeOrValueType,
assertEach,
chain,
assertOneOf,
validateOptional,
} from "./utils";
defineType("ArrayExpression", {
@ -1152,3 +1155,838 @@ defineType("WithStatement", {
},
},
});
// --- ES2015 ---
defineType("AssignmentPattern", {
visitor: ["left", "right", "decorators" /* for legacy param decorators */],
builder: ["left", "right"],
aliases: ["Pattern", "PatternLike", "LVal"],
fields: {
...patternLikeCommon,
left: {
validate: assertNodeType(
"Identifier",
"ObjectPattern",
"ArrayPattern",
"MemberExpression",
),
},
right: {
validate: assertNodeType("Expression"),
},
// For TypeScript
decorators: {
validate: chain(
assertValueType("array"),
assertEach(assertNodeType("Decorator")),
),
optional: true,
},
},
});
defineType("ArrayPattern", {
visitor: ["elements", "typeAnnotation"],
builder: ["elements"],
aliases: ["Pattern", "PatternLike", "LVal"],
fields: {
...patternLikeCommon,
elements: {
validate: chain(
assertValueType("array"),
assertEach(assertNodeOrValueType("null", "PatternLike")),
),
},
// For TypeScript
decorators: {
validate: chain(
assertValueType("array"),
assertEach(assertNodeType("Decorator")),
),
optional: true,
},
},
});
defineType("ArrowFunctionExpression", {
builder: ["params", "body", "async"],
visitor: ["params", "body", "returnType", "typeParameters"],
aliases: [
"Scopable",
"Function",
"BlockParent",
"FunctionParent",
"Expression",
"Pureish",
],
fields: {
...functionCommon,
...functionTypeAnnotationCommon,
expression: {
// https://github.com/babel/babylon/issues/505
validate: assertValueType("boolean"),
},
body: {
validate: assertNodeType("BlockStatement", "Expression"),
},
},
});
defineType("ClassBody", {
visitor: ["body"],
fields: {
body: {
validate: chain(
assertValueType("array"),
assertEach(
assertNodeType(
"ClassMethod",
"ClassPrivateMethod",
"ClassProperty",
"ClassPrivateProperty",
"TSDeclareMethod",
"TSIndexSignature",
),
),
),
},
},
});
defineType("ClassExpression", {
builder: ["id", "superClass", "body", "decorators"],
visitor: [
"id",
"body",
"superClass",
"mixins",
"typeParameters",
"superTypeParameters",
"implements",
"decorators",
],
aliases: ["Scopable", "Class", "Expression"],
fields: {
id: {
validate: assertNodeType("Identifier"),
// In declarations, this is missing if this is the
// child of an ExportDefaultDeclaration.
optional: true,
},
typeParameters: {
validate: assertNodeType(
"TypeParameterDeclaration",
"TSTypeParameterDeclaration",
"Noop",
),
optional: true,
},
body: {
validate: assertNodeType("ClassBody"),
},
superClass: {
optional: true,
validate: assertNodeType("Expression"),
},
superTypeParameters: {
validate: assertNodeType(
"TypeParameterInstantiation",
"TSTypeParameterInstantiation",
),
optional: true,
},
implements: {
validate: chain(
assertValueType("array"),
assertEach(
assertNodeType("TSExpressionWithTypeArguments", "ClassImplements"),
),
),
optional: true,
},
decorators: {
validate: chain(
assertValueType("array"),
assertEach(assertNodeType("Decorator")),
),
optional: true,
},
mixins: {
validate: assertNodeType("InterfaceExtends"),
optional: true,
},
},
});
defineType("ClassDeclaration", {
inherits: "ClassExpression",
aliases: ["Scopable", "Class", "Statement", "Declaration"],
fields: {
id: {
validate: assertNodeType("Identifier"),
},
typeParameters: {
validate: assertNodeType(
"TypeParameterDeclaration",
"TSTypeParameterDeclaration",
"Noop",
),
optional: true,
},
body: {
validate: assertNodeType("ClassBody"),
},
superClass: {
optional: true,
validate: assertNodeType("Expression"),
},
superTypeParameters: {
validate: assertNodeType(
"TypeParameterInstantiation",
"TSTypeParameterInstantiation",
),
optional: true,
},
implements: {
validate: chain(
assertValueType("array"),
assertEach(
assertNodeType("TSExpressionWithTypeArguments", "ClassImplements"),
),
),
optional: true,
},
decorators: {
validate: chain(
assertValueType("array"),
assertEach(assertNodeType("Decorator")),
),
optional: true,
},
mixins: {
validate: assertNodeType("InterfaceExtends"),
optional: true,
},
declare: {
validate: assertValueType("boolean"),
optional: true,
},
abstract: {
validate: assertValueType("boolean"),
optional: true,
},
},
validate: (function () {
const identifier = assertNodeType("Identifier");
return function (parent, key, node) {
if (!process.env.BABEL_TYPES_8_BREAKING) return;
if (!is("ExportDefaultDeclaration", parent)) {
identifier(node, "id", node.id);
}
};
})(),
});
defineType("ExportAllDeclaration", {
visitor: ["source"],
aliases: [
"Statement",
"Declaration",
"ModuleDeclaration",
"ExportDeclaration",
],
fields: {
source: {
validate: assertNodeType("StringLiteral"),
},
},
});
defineType("ExportDefaultDeclaration", {
visitor: ["declaration"],
aliases: [
"Statement",
"Declaration",
"ModuleDeclaration",
"ExportDeclaration",
],
fields: {
declaration: {
validate: assertNodeType(
"FunctionDeclaration",
"TSDeclareFunction",
"ClassDeclaration",
"Expression",
),
},
},
});
defineType("ExportNamedDeclaration", {
visitor: ["declaration", "specifiers", "source"],
aliases: [
"Statement",
"Declaration",
"ModuleDeclaration",
"ExportDeclaration",
],
fields: {
declaration: {
optional: true,
validate: chain(
assertNodeType("Declaration"),
Object.assign(
function (node, key, val) {
if (!process.env.BABEL_TYPES_8_BREAKING) return;
// This validator isn't put at the top level because we can run it
// even if this node doesn't have a parent.
if (val && node.specifiers.length) {
throw new TypeError(
"Only declaration or specifiers is allowed on ExportNamedDeclaration",
);
}
},
{ oneOfNodeTypes: ["Declaration"] },
),
function (node, key, val) {
if (!process.env.BABEL_TYPES_8_BREAKING) return;
// This validator isn't put at the top level because we can run it
// even if this node doesn't have a parent.
if (val && node.source) {
throw new TypeError("Cannot export a declaration from a source");
}
},
),
},
specifiers: {
default: [],
validate: chain(
assertValueType("array"),
assertEach(
(function () {
const sourced = assertNodeType(
"ExportSpecifier",
"ExportDefaultSpecifier",
"ExportNamespaceSpecifier",
);
const sourceless = assertNodeType("ExportSpecifier");
if (!process.env.BABEL_TYPES_8_BREAKING) return sourced;
return function (node, key, val) {
const validator = node.source ? sourced : sourceless;
validator(node, key, val);
};
})(),
),
),
},
source: {
validate: assertNodeType("StringLiteral"),
optional: true,
},
exportKind: validateOptional(assertOneOf("type", "value")),
},
});
defineType("ExportSpecifier", {
visitor: ["local", "exported"],
aliases: ["ModuleSpecifier"],
fields: {
local: {
validate: assertNodeType("Identifier"),
},
exported: {
validate: assertNodeType("Identifier"),
},
},
});
defineType("ForOfStatement", {
visitor: ["left", "right", "body"],
builder: ["left", "right", "body", "await"],
aliases: [
"Scopable",
"Statement",
"For",
"BlockParent",
"Loop",
"ForXStatement",
],
fields: {
left: {
validate: (function () {
if (!process.env.BABEL_TYPES_8_BREAKING) {
return assertNodeType("VariableDeclaration", "LVal");
}
const declaration = assertNodeType("VariableDeclaration");
const lval = assertNodeType(
"Identifier",
"MemberExpression",
"ArrayPattern",
"ObjectPattern",
);
return function (node, key, val) {
if (is("VariableDeclaration", val)) {
declaration(node, key, val);
} else {
lval(node, key, val);
}
};
})(),
},
right: {
validate: assertNodeType("Expression"),
},
body: {
validate: assertNodeType("Statement"),
},
await: {
default: false,
},
},
});
defineType("ImportDeclaration", {
visitor: ["specifiers", "source"],
aliases: ["Statement", "Declaration", "ModuleDeclaration"],
fields: {
specifiers: {
validate: chain(
assertValueType("array"),
assertEach(
assertNodeType(
"ImportSpecifier",
"ImportDefaultSpecifier",
"ImportNamespaceSpecifier",
),
),
),
},
source: {
validate: assertNodeType("StringLiteral"),
},
importKind: {
// Handle TypeScript/Flowtype's extension "import type foo from"
// TypeScript doesn't support typeof
validate: assertOneOf("type", "typeof", "value"),
optional: true,
},
},
});
defineType("ImportDefaultSpecifier", {
visitor: ["local"],
aliases: ["ModuleSpecifier"],
fields: {
local: {
validate: assertNodeType("Identifier"),
},
},
});
defineType("ImportNamespaceSpecifier", {
visitor: ["local"],
aliases: ["ModuleSpecifier"],
fields: {
local: {
validate: assertNodeType("Identifier"),
},
},
});
defineType("ImportSpecifier", {
visitor: ["local", "imported"],
aliases: ["ModuleSpecifier"],
fields: {
local: {
validate: assertNodeType("Identifier"),
},
imported: {
validate: assertNodeType("Identifier"),
},
importKind: {
// Handle Flowtype's extension "import {typeof foo} from"
validate: assertOneOf("type", "typeof"),
optional: true,
},
},
});
defineType("MetaProperty", {
visitor: ["meta", "property"],
aliases: ["Expression"],
fields: {
meta: {
validate: chain(
assertNodeType("Identifier"),
Object.assign(
function (node, key, val) {
if (!process.env.BABEL_TYPES_8_BREAKING) return;
let property;
switch (val.name) {
case "function":
property = "sent";
break;
case "new":
property = "target";
break;
case "import":
property = "meta";
break;
}
if (!is("Identifier", node.property, { name: property })) {
throw new TypeError("Unrecognised MetaProperty");
}
},
{ oneOfNodeTypes: ["Identifier"] },
),
),
},
property: {
validate: assertNodeType("Identifier"),
},
},
});
export const classMethodOrPropertyCommon = {
abstract: {
validate: assertValueType("boolean"),
optional: true,
},
accessibility: {
validate: assertOneOf("public", "private", "protected"),
optional: true,
},
static: {
default: false,
},
computed: {
default: false,
},
optional: {
validate: assertValueType("boolean"),
optional: true,
},
key: {
validate: chain(
(function () {
const normal = assertNodeType(
"Identifier",
"StringLiteral",
"NumericLiteral",
);
const computed = assertNodeType("Expression");
return function (node: Object, key: string, val: any) {
const validator = node.computed ? computed : normal;
validator(node, key, val);
};
})(),
assertNodeType(
"Identifier",
"StringLiteral",
"NumericLiteral",
"Expression",
),
),
},
};
export const classMethodOrDeclareMethodCommon = {
...functionCommon,
...classMethodOrPropertyCommon,
kind: {
validate: assertOneOf("get", "set", "method", "constructor"),
default: "method",
},
access: {
validate: chain(
assertValueType("string"),
assertOneOf("public", "private", "protected"),
),
optional: true,
},
decorators: {
validate: chain(
assertValueType("array"),
assertEach(assertNodeType("Decorator")),
),
optional: true,
},
};
defineType("ClassMethod", {
aliases: ["Function", "Scopable", "BlockParent", "FunctionParent", "Method"],
builder: [
"kind",
"key",
"params",
"body",
"computed",
"static",
"generator",
"async",
],
visitor: [
"key",
"params",
"body",
"decorators",
"returnType",
"typeParameters",
],
fields: {
...classMethodOrDeclareMethodCommon,
...functionTypeAnnotationCommon,
body: {
validate: assertNodeType("BlockStatement"),
},
},
});
defineType("ObjectPattern", {
visitor: [
"properties",
"typeAnnotation",
"decorators" /* for legacy param decorators */,
],
builder: ["properties"],
aliases: ["Pattern", "PatternLike", "LVal"],
fields: {
...patternLikeCommon,
properties: {
validate: chain(
assertValueType("array"),
assertEach(assertNodeType("RestElement", "ObjectProperty")),
),
},
},
});
defineType("SpreadElement", {
visitor: ["argument"],
aliases: ["UnaryLike"],
deprecatedAlias: "SpreadProperty",
fields: {
argument: {
validate: assertNodeType("Expression"),
},
},
});
defineType("Super", {
aliases: ["Expression"],
});
defineType("TaggedTemplateExpression", {
visitor: ["tag", "quasi"],
aliases: ["Expression"],
fields: {
tag: {
validate: assertNodeType("Expression"),
},
quasi: {
validate: assertNodeType("TemplateLiteral"),
},
typeParameters: {
validate: assertNodeType(
"TypeParameterInstantiation",
"TSTypeParameterInstantiation",
),
optional: true,
},
},
});
defineType("TemplateElement", {
builder: ["value", "tail"],
fields: {
value: {
validate: assertShape({
raw: {
validate: assertValueType("string"),
},
cooked: {
validate: assertValueType("string"),
optional: true,
},
}),
},
tail: {
default: false,
},
},
});
defineType("TemplateLiteral", {
visitor: ["quasis", "expressions"],
aliases: ["Expression", "Literal"],
fields: {
quasis: {
validate: chain(
assertValueType("array"),
assertEach(assertNodeType("TemplateElement")),
),
},
expressions: {
validate: chain(
assertValueType("array"),
assertEach(assertNodeType("Expression")),
function (node, key, val) {
if (node.quasis.length !== val.length + 1) {
throw new TypeError(
`Number of ${
node.type
} quasis should be exactly one more than the number of expressions.\nExpected ${
val.length + 1
} quasis but got ${node.quasis.length}`,
);
}
},
),
},
},
});
defineType("YieldExpression", {
builder: ["argument", "delegate"],
visitor: ["argument"],
aliases: ["Expression", "Terminatorless"],
fields: {
delegate: {
validate: chain(
assertValueType("boolean"),
Object.assign(
function (node, key, val) {
if (!process.env.BABEL_TYPES_8_BREAKING) return;
if (val && !node.argument) {
throw new TypeError(
"Property delegate of YieldExpression cannot be true if there is no argument",
);
}
},
{ type: "boolean" },
),
),
default: false,
},
argument: {
optional: true,
validate: assertNodeType("Expression"),
},
},
});
// --- ES2017 ---
defineType("AwaitExpression", {
builder: ["argument"],
visitor: ["argument"],
aliases: ["Expression", "Terminatorless"],
fields: {
argument: {
validate: assertNodeType("Expression"),
},
},
});
// --- ES2019 ---
defineType("Import", {
aliases: ["Expression"],
});
// --- ES2020 ---
defineType("BigIntLiteral", {
builder: ["value"],
fields: {
value: {
validate: assertValueType("string"),
},
},
aliases: ["Expression", "Pureish", "Literal", "Immutable"],
});
defineType("ExportNamespaceSpecifier", {
visitor: ["exported"],
aliases: ["ModuleSpecifier"],
fields: {
exported: {
validate: assertNodeType("Identifier"),
},
},
});
defineType("OptionalMemberExpression", {
builder: ["object", "property", "computed", "optional"],
visitor: ["object", "property"],
aliases: ["Expression"],
fields: {
object: {
validate: assertNodeType("Expression"),
},
property: {
validate: (function () {
const normal = assertNodeType("Identifier");
const computed = assertNodeType("Expression");
const validator = function (node, key, val) {
const validator = node.computed ? computed : normal;
validator(node, key, val);
};
// todo(ts): can be discriminated union by `computed` property
validator.oneOfNodeTypes = ["Expression", "Identifier"];
return validator;
})(),
},
computed: {
default: false,
},
optional: {
validate: !process.env.BABEL_TYPES_8_BREAKING
? assertValueType("boolean")
: chain(assertValueType("boolean"), assertOptionalChainStart()),
},
},
});
defineType("OptionalCallExpression", {
visitor: ["callee", "arguments", "typeParameters", "typeArguments"],
builder: ["callee", "arguments", "optional"],
aliases: ["Expression"],
fields: {
callee: {
validate: assertNodeType("Expression"),
},
arguments: {
validate: chain(
assertValueType("array"),
assertEach(
assertNodeType("Expression", "SpreadElement", "JSXNamespacedName"),
),
),
},
optional: {
validate: !process.env.BABEL_TYPES_8_BREAKING
? assertValueType("boolean")
: chain(assertValueType("boolean"), assertOptionalChainStart()),
},
typeArguments: {
validate: assertNodeType("TypeParameterInstantiation"),
optional: true,
},
typeParameters: {
validate: assertNodeType("TSTypeParameterInstantiation"),
optional: true,
},
},
});

View File

@ -1,748 +0,0 @@
// @flow
import defineType, {
assertShape,
assertNodeType,
assertValueType,
assertNodeOrValueType,
chain,
assertEach,
assertOneOf,
validateOptional,
} from "./utils";
import {
functionCommon,
functionTypeAnnotationCommon,
patternLikeCommon,
} from "./core";
import is from "../validators/is";
defineType("AssignmentPattern", {
visitor: ["left", "right", "decorators" /* for legacy param decorators */],
builder: ["left", "right"],
aliases: ["Pattern", "PatternLike", "LVal"],
fields: {
...patternLikeCommon,
left: {
validate: assertNodeType(
"Identifier",
"ObjectPattern",
"ArrayPattern",
"MemberExpression",
),
},
right: {
validate: assertNodeType("Expression"),
},
// For TypeScript
decorators: {
validate: chain(
assertValueType("array"),
assertEach(assertNodeType("Decorator")),
),
optional: true,
},
},
});
defineType("ArrayPattern", {
visitor: ["elements", "typeAnnotation"],
builder: ["elements"],
aliases: ["Pattern", "PatternLike", "LVal"],
fields: {
...patternLikeCommon,
elements: {
validate: chain(
assertValueType("array"),
assertEach(assertNodeOrValueType("null", "PatternLike")),
),
},
// For TypeScript
decorators: {
validate: chain(
assertValueType("array"),
assertEach(assertNodeType("Decorator")),
),
optional: true,
},
},
});
defineType("ArrowFunctionExpression", {
builder: ["params", "body", "async"],
visitor: ["params", "body", "returnType", "typeParameters"],
aliases: [
"Scopable",
"Function",
"BlockParent",
"FunctionParent",
"Expression",
"Pureish",
],
fields: {
...functionCommon,
...functionTypeAnnotationCommon,
expression: {
// https://github.com/babel/babylon/issues/505
validate: assertValueType("boolean"),
},
body: {
validate: assertNodeType("BlockStatement", "Expression"),
},
},
});
defineType("ClassBody", {
visitor: ["body"],
fields: {
body: {
validate: chain(
assertValueType("array"),
assertEach(
assertNodeType(
"ClassMethod",
"ClassPrivateMethod",
"ClassProperty",
"ClassPrivateProperty",
"TSDeclareMethod",
"TSIndexSignature",
),
),
),
},
},
});
defineType("ClassExpression", {
builder: ["id", "superClass", "body", "decorators"],
visitor: [
"id",
"body",
"superClass",
"mixins",
"typeParameters",
"superTypeParameters",
"implements",
"decorators",
],
aliases: ["Scopable", "Class", "Expression"],
fields: {
id: {
validate: assertNodeType("Identifier"),
// In declarations, this is missing if this is the
// child of an ExportDefaultDeclaration.
optional: true,
},
typeParameters: {
validate: assertNodeType(
"TypeParameterDeclaration",
"TSTypeParameterDeclaration",
"Noop",
),
optional: true,
},
body: {
validate: assertNodeType("ClassBody"),
},
superClass: {
optional: true,
validate: assertNodeType("Expression"),
},
superTypeParameters: {
validate: assertNodeType(
"TypeParameterInstantiation",
"TSTypeParameterInstantiation",
),
optional: true,
},
implements: {
validate: chain(
assertValueType("array"),
assertEach(
assertNodeType("TSExpressionWithTypeArguments", "ClassImplements"),
),
),
optional: true,
},
decorators: {
validate: chain(
assertValueType("array"),
assertEach(assertNodeType("Decorator")),
),
optional: true,
},
mixins: {
validate: assertNodeType("InterfaceExtends"),
optional: true,
},
},
});
defineType("ClassDeclaration", {
inherits: "ClassExpression",
aliases: ["Scopable", "Class", "Statement", "Declaration"],
fields: {
id: {
validate: assertNodeType("Identifier"),
},
typeParameters: {
validate: assertNodeType(
"TypeParameterDeclaration",
"TSTypeParameterDeclaration",
"Noop",
),
optional: true,
},
body: {
validate: assertNodeType("ClassBody"),
},
superClass: {
optional: true,
validate: assertNodeType("Expression"),
},
superTypeParameters: {
validate: assertNodeType(
"TypeParameterInstantiation",
"TSTypeParameterInstantiation",
),
optional: true,
},
implements: {
validate: chain(
assertValueType("array"),
assertEach(
assertNodeType("TSExpressionWithTypeArguments", "ClassImplements"),
),
),
optional: true,
},
decorators: {
validate: chain(
assertValueType("array"),
assertEach(assertNodeType("Decorator")),
),
optional: true,
},
mixins: {
validate: assertNodeType("InterfaceExtends"),
optional: true,
},
declare: {
validate: assertValueType("boolean"),
optional: true,
},
abstract: {
validate: assertValueType("boolean"),
optional: true,
},
},
validate: (function () {
const identifier = assertNodeType("Identifier");
return function (parent, key, node) {
if (!process.env.BABEL_TYPES_8_BREAKING) return;
if (!is("ExportDefaultDeclaration", parent)) {
identifier(node, "id", node.id);
}
};
})(),
});
defineType("ExportAllDeclaration", {
visitor: ["source"],
aliases: [
"Statement",
"Declaration",
"ModuleDeclaration",
"ExportDeclaration",
],
fields: {
source: {
validate: assertNodeType("StringLiteral"),
},
},
});
defineType("ExportDefaultDeclaration", {
visitor: ["declaration"],
aliases: [
"Statement",
"Declaration",
"ModuleDeclaration",
"ExportDeclaration",
],
fields: {
declaration: {
validate: assertNodeType(
"FunctionDeclaration",
"TSDeclareFunction",
"ClassDeclaration",
"Expression",
),
},
},
});
defineType("ExportNamedDeclaration", {
visitor: ["declaration", "specifiers", "source"],
aliases: [
"Statement",
"Declaration",
"ModuleDeclaration",
"ExportDeclaration",
],
fields: {
declaration: {
optional: true,
validate: chain(
assertNodeType("Declaration"),
Object.assign(
function (node, key, val) {
if (!process.env.BABEL_TYPES_8_BREAKING) return;
// This validator isn't put at the top level because we can run it
// even if this node doesn't have a parent.
if (val && node.specifiers.length) {
throw new TypeError(
"Only declaration or specifiers is allowed on ExportNamedDeclaration",
);
}
},
{ oneOfNodeTypes: ["Declaration"] },
),
function (node, key, val) {
if (!process.env.BABEL_TYPES_8_BREAKING) return;
// This validator isn't put at the top level because we can run it
// even if this node doesn't have a parent.
if (val && node.source) {
throw new TypeError("Cannot export a declaration from a source");
}
},
),
},
specifiers: {
default: [],
validate: chain(
assertValueType("array"),
assertEach(
(function () {
const sourced = assertNodeType(
"ExportSpecifier",
"ExportDefaultSpecifier",
"ExportNamespaceSpecifier",
);
const sourceless = assertNodeType("ExportSpecifier");
if (!process.env.BABEL_TYPES_8_BREAKING) return sourced;
return function (node, key, val) {
const validator = node.source ? sourced : sourceless;
validator(node, key, val);
};
})(),
),
),
},
source: {
validate: assertNodeType("StringLiteral"),
optional: true,
},
exportKind: validateOptional(assertOneOf("type", "value")),
},
});
defineType("ExportSpecifier", {
visitor: ["local", "exported"],
aliases: ["ModuleSpecifier"],
fields: {
local: {
validate: assertNodeType("Identifier"),
},
exported: {
validate: assertNodeType("Identifier"),
},
},
});
defineType("ForOfStatement", {
visitor: ["left", "right", "body"],
builder: ["left", "right", "body", "await"],
aliases: [
"Scopable",
"Statement",
"For",
"BlockParent",
"Loop",
"ForXStatement",
],
fields: {
left: {
validate: (function () {
if (!process.env.BABEL_TYPES_8_BREAKING) {
return assertNodeType("VariableDeclaration", "LVal");
}
const declaration = assertNodeType("VariableDeclaration");
const lval = assertNodeType(
"Identifier",
"MemberExpression",
"ArrayPattern",
"ObjectPattern",
);
return function (node, key, val) {
if (is("VariableDeclaration", val)) {
declaration(node, key, val);
} else {
lval(node, key, val);
}
};
})(),
},
right: {
validate: assertNodeType("Expression"),
},
body: {
validate: assertNodeType("Statement"),
},
await: {
default: false,
},
},
});
defineType("ImportDeclaration", {
visitor: ["specifiers", "source"],
aliases: ["Statement", "Declaration", "ModuleDeclaration"],
fields: {
specifiers: {
validate: chain(
assertValueType("array"),
assertEach(
assertNodeType(
"ImportSpecifier",
"ImportDefaultSpecifier",
"ImportNamespaceSpecifier",
),
),
),
},
source: {
validate: assertNodeType("StringLiteral"),
},
importKind: {
// Handle TypeScript/Flowtype's extension "import type foo from"
// TypeScript doesn't support typeof
validate: assertOneOf("type", "typeof", "value"),
optional: true,
},
},
});
defineType("ImportDefaultSpecifier", {
visitor: ["local"],
aliases: ["ModuleSpecifier"],
fields: {
local: {
validate: assertNodeType("Identifier"),
},
},
});
defineType("ImportNamespaceSpecifier", {
visitor: ["local"],
aliases: ["ModuleSpecifier"],
fields: {
local: {
validate: assertNodeType("Identifier"),
},
},
});
defineType("ImportSpecifier", {
visitor: ["local", "imported"],
aliases: ["ModuleSpecifier"],
fields: {
local: {
validate: assertNodeType("Identifier"),
},
imported: {
validate: assertNodeType("Identifier"),
},
importKind: {
// Handle Flowtype's extension "import {typeof foo} from"
validate: assertOneOf("type", "typeof"),
optional: true,
},
},
});
defineType("MetaProperty", {
visitor: ["meta", "property"],
aliases: ["Expression"],
fields: {
meta: {
validate: chain(
assertNodeType("Identifier"),
Object.assign(
function (node, key, val) {
if (!process.env.BABEL_TYPES_8_BREAKING) return;
let property;
switch (val.name) {
case "function":
property = "sent";
break;
case "new":
property = "target";
break;
case "import":
property = "meta";
break;
}
if (!is("Identifier", node.property, { name: property })) {
throw new TypeError("Unrecognised MetaProperty");
}
},
{ oneOfNodeTypes: ["Identifier"] },
),
),
},
property: {
validate: assertNodeType("Identifier"),
},
},
});
export const classMethodOrPropertyCommon = {
abstract: {
validate: assertValueType("boolean"),
optional: true,
},
accessibility: {
validate: assertOneOf("public", "private", "protected"),
optional: true,
},
static: {
default: false,
},
computed: {
default: false,
},
optional: {
validate: assertValueType("boolean"),
optional: true,
},
key: {
validate: chain(
(function () {
const normal = assertNodeType(
"Identifier",
"StringLiteral",
"NumericLiteral",
);
const computed = assertNodeType("Expression");
return function (node: Object, key: string, val: any) {
const validator = node.computed ? computed : normal;
validator(node, key, val);
};
})(),
assertNodeType(
"Identifier",
"StringLiteral",
"NumericLiteral",
"Expression",
),
),
},
};
export const classMethodOrDeclareMethodCommon = {
...functionCommon,
...classMethodOrPropertyCommon,
kind: {
validate: assertOneOf("get", "set", "method", "constructor"),
default: "method",
},
access: {
validate: chain(
assertValueType("string"),
assertOneOf("public", "private", "protected"),
),
optional: true,
},
decorators: {
validate: chain(
assertValueType("array"),
assertEach(assertNodeType("Decorator")),
),
optional: true,
},
};
defineType("ClassMethod", {
aliases: ["Function", "Scopable", "BlockParent", "FunctionParent", "Method"],
builder: [
"kind",
"key",
"params",
"body",
"computed",
"static",
"generator",
"async",
],
visitor: [
"key",
"params",
"body",
"decorators",
"returnType",
"typeParameters",
],
fields: {
...classMethodOrDeclareMethodCommon,
...functionTypeAnnotationCommon,
body: {
validate: assertNodeType("BlockStatement"),
},
},
});
defineType("ObjectPattern", {
visitor: [
"properties",
"typeAnnotation",
"decorators" /* for legacy param decorators */,
],
builder: ["properties"],
aliases: ["Pattern", "PatternLike", "LVal"],
fields: {
...patternLikeCommon,
properties: {
validate: chain(
assertValueType("array"),
assertEach(assertNodeType("RestElement", "ObjectProperty")),
),
},
},
});
defineType("SpreadElement", {
visitor: ["argument"],
aliases: ["UnaryLike"],
deprecatedAlias: "SpreadProperty",
fields: {
argument: {
validate: assertNodeType("Expression"),
},
},
});
defineType("Super", {
aliases: ["Expression"],
});
defineType("TaggedTemplateExpression", {
visitor: ["tag", "quasi"],
aliases: ["Expression"],
fields: {
tag: {
validate: assertNodeType("Expression"),
},
quasi: {
validate: assertNodeType("TemplateLiteral"),
},
typeParameters: {
validate: assertNodeType(
"TypeParameterInstantiation",
"TSTypeParameterInstantiation",
),
optional: true,
},
},
});
defineType("TemplateElement", {
builder: ["value", "tail"],
fields: {
value: {
validate: assertShape({
raw: {
validate: assertValueType("string"),
},
cooked: {
validate: assertValueType("string"),
optional: true,
},
}),
},
tail: {
default: false,
},
},
});
defineType("TemplateLiteral", {
visitor: ["quasis", "expressions"],
aliases: ["Expression", "Literal"],
fields: {
quasis: {
validate: chain(
assertValueType("array"),
assertEach(assertNodeType("TemplateElement")),
),
},
expressions: {
validate: chain(
assertValueType("array"),
assertEach(assertNodeType("Expression")),
function (node, key, val) {
if (node.quasis.length !== val.length + 1) {
throw new TypeError(
`Number of ${
node.type
} quasis should be exactly one more than the number of expressions.\nExpected ${
val.length + 1
} quasis but got ${node.quasis.length}`,
);
}
},
),
},
},
});
defineType("YieldExpression", {
builder: ["argument", "delegate"],
visitor: ["argument"],
aliases: ["Expression", "Terminatorless"],
fields: {
delegate: {
validate: chain(
assertValueType("boolean"),
Object.assign(
function (node, key, val) {
if (!process.env.BABEL_TYPES_8_BREAKING) return;
if (val && !node.argument) {
throw new TypeError(
"Property delegate of YieldExpression cannot be true if there is no argument",
);
}
},
{ type: "boolean" },
),
),
default: false,
},
argument: {
optional: true,
validate: assertNodeType("Expression"),
},
},
});

View File

@ -1,6 +1,5 @@
// @flow
import defineType, {
assertOptionalChainStart,
assertEach,
assertNodeType,
assertValueType,
@ -9,22 +8,11 @@ import defineType, {
import {
classMethodOrPropertyCommon,
classMethodOrDeclareMethodCommon,
} from "./es2015";
import { functionTypeAnnotationCommon } from "./core";
functionTypeAnnotationCommon,
} from "./core";
defineType("ArgumentPlaceholder", {});
defineType("AwaitExpression", {
builder: ["argument"],
visitor: ["argument"],
aliases: ["Expression", "Terminatorless"],
fields: {
argument: {
validate: assertNodeType("Expression"),
},
},
});
defineType("BindExpression", {
visitor: ["object", "callee"],
aliases: ["Expression"],
@ -94,39 +82,6 @@ defineType("ClassProperty", {
},
});
defineType("OptionalMemberExpression", {
builder: ["object", "property", "computed", "optional"],
visitor: ["object", "property"],
aliases: ["Expression"],
fields: {
object: {
validate: assertNodeType("Expression"),
},
property: {
validate: (function () {
const normal = assertNodeType("Identifier");
const computed = assertNodeType("Expression");
const validator = function (node, key, val) {
const validator = node.computed ? computed : normal;
validator(node, key, val);
};
// todo(ts): can be discriminated union by `computed` property
validator.oneOfNodeTypes = ["Expression", "Identifier"];
return validator;
})(),
},
computed: {
default: false,
},
optional: {
validate: !process.env.BABEL_TYPES_8_BREAKING
? assertValueType("boolean")
: chain(assertValueType("boolean"), assertOptionalChainStart()),
},
},
});
defineType("PipelineTopicExpression", {
builder: ["expression"],
visitor: ["expression"],
@ -151,38 +106,6 @@ defineType("PipelinePrimaryTopicReference", {
aliases: ["Expression"],
});
defineType("OptionalCallExpression", {
visitor: ["callee", "arguments", "typeParameters", "typeArguments"],
builder: ["callee", "arguments", "optional"],
aliases: ["Expression"],
fields: {
callee: {
validate: assertNodeType("Expression"),
},
arguments: {
validate: chain(
assertValueType("array"),
assertEach(
assertNodeType("Expression", "SpreadElement", "JSXNamespacedName"),
),
),
},
optional: {
validate: !process.env.BABEL_TYPES_8_BREAKING
? assertValueType("boolean")
: chain(assertValueType("boolean"), assertOptionalChainStart()),
},
typeArguments: {
validate: assertNodeType("TypeParameterInstantiation"),
optional: true,
},
typeParameters: {
validate: assertNodeType("TSTypeParameterInstantiation"),
optional: true,
},
},
});
defineType("ClassPrivateProperty", {
visitor: ["key", "value", "decorators"],
builder: ["key", "value", "decorators"],
@ -235,10 +158,6 @@ defineType("ClassPrivateMethod", {
},
});
defineType("Import", {
aliases: ["Expression"],
});
defineType("ImportAttribute", {
visitor: ["key", "value"],
fields: {
@ -280,16 +199,6 @@ defineType("ExportDefaultSpecifier", {
},
});
defineType("ExportNamespaceSpecifier", {
visitor: ["exported"],
aliases: ["ModuleSpecifier"],
fields: {
exported: {
validate: assertNodeType("Identifier"),
},
},
});
defineType("PrivateName", {
visitor: ["id"],
aliases: ["Private"],
@ -300,16 +209,6 @@ defineType("PrivateName", {
},
});
defineType("BigIntLiteral", {
builder: ["value"],
fields: {
value: {
validate: assertValueType("string"),
},
},
aliases: ["Expression", "Pureish", "Literal", "Immutable"],
});
defineType("RecordExpression", {
visitor: ["properties"],
aliases: ["Expression"],

View File

@ -1,7 +1,6 @@
// @flow
import toFastProperties from "to-fast-properties";
import "./core";
import "./es2015";
import "./flow";
import "./jsx";
import "./misc";

View File

@ -12,8 +12,10 @@ import defineType, {
validateOptionalType,
validateType,
} from "./utils";
import { functionDeclarationCommon } from "./core";
import { classMethodOrDeclareMethodCommon } from "./es2015";
import {
functionDeclarationCommon,
classMethodOrDeclareMethodCommon,
} from "./core";
const bool = assertValueType("boolean");

View File

@ -1076,6 +1076,99 @@ export function isYieldExpression(node: ?Object, opts?: Object): boolean {
return false;
}
export function isAwaitExpression(node: ?Object, opts?: Object): boolean {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "AwaitExpression") {
if (typeof opts === "undefined") {
return true;
} else {
return shallowEqual(node, opts);
}
}
return false;
}
export function isImport(node: ?Object, opts?: Object): boolean {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "Import") {
if (typeof opts === "undefined") {
return true;
} else {
return shallowEqual(node, opts);
}
}
return false;
}
export function isBigIntLiteral(node: ?Object, opts?: Object): boolean {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "BigIntLiteral") {
if (typeof opts === "undefined") {
return true;
} else {
return shallowEqual(node, opts);
}
}
return false;
}
export function isExportNamespaceSpecifier(
node: ?Object,
opts?: Object,
): boolean {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "ExportNamespaceSpecifier") {
if (typeof opts === "undefined") {
return true;
} else {
return shallowEqual(node, opts);
}
}
return false;
}
export function isOptionalMemberExpression(
node: ?Object,
opts?: Object,
): boolean {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "OptionalMemberExpression") {
if (typeof opts === "undefined") {
return true;
} else {
return shallowEqual(node, opts);
}
}
return false;
}
export function isOptionalCallExpression(
node: ?Object,
opts?: Object,
): boolean {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "OptionalCallExpression") {
if (typeof opts === "undefined") {
return true;
} else {
return shallowEqual(node, opts);
}
}
return false;
}
export function isAnyTypeAnnotation(node: ?Object, opts?: Object): boolean {
if (!node) return false;
@ -2275,20 +2368,6 @@ export function isArgumentPlaceholder(node: ?Object, opts?: Object): boolean {
return false;
}
export function isAwaitExpression(node: ?Object, opts?: Object): boolean {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "AwaitExpression") {
if (typeof opts === "undefined") {
return true;
} else {
return shallowEqual(node, opts);
}
}
return false;
}
export function isBindExpression(node: ?Object, opts?: Object): boolean {
if (!node) return false;
@ -2317,23 +2396,6 @@ export function isClassProperty(node: ?Object, opts?: Object): boolean {
return false;
}
export function isOptionalMemberExpression(
node: ?Object,
opts?: Object,
): boolean {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "OptionalMemberExpression") {
if (typeof opts === "undefined") {
return true;
} else {
return shallowEqual(node, opts);
}
}
return false;
}
export function isPipelineTopicExpression(
node: ?Object,
opts?: Object,
@ -2382,23 +2444,6 @@ export function isPipelinePrimaryTopicReference(
return false;
}
export function isOptionalCallExpression(
node: ?Object,
opts?: Object,
): boolean {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "OptionalCallExpression") {
if (typeof opts === "undefined") {
return true;
} else {
return shallowEqual(node, opts);
}
}
return false;
}
export function isClassPrivateProperty(node: ?Object, opts?: Object): boolean {
if (!node) return false;
@ -2427,20 +2472,6 @@ export function isClassPrivateMethod(node: ?Object, opts?: Object): boolean {
return false;
}
export function isImport(node: ?Object, opts?: Object): boolean {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "Import") {
if (typeof opts === "undefined") {
return true;
} else {
return shallowEqual(node, opts);
}
}
return false;
}
export function isImportAttribute(node: ?Object, opts?: Object): boolean {
if (!node) return false;
@ -2500,23 +2531,6 @@ export function isExportDefaultSpecifier(
return false;
}
export function isExportNamespaceSpecifier(
node: ?Object,
opts?: Object,
): boolean {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "ExportNamespaceSpecifier") {
if (typeof opts === "undefined") {
return true;
} else {
return shallowEqual(node, opts);
}
}
return false;
}
export function isPrivateName(node: ?Object, opts?: Object): boolean {
if (!node) return false;
@ -2531,20 +2545,6 @@ export function isPrivateName(node: ?Object, opts?: Object): boolean {
return false;
}
export function isBigIntLiteral(node: ?Object, opts?: Object): boolean {
if (!node) return false;
const nodeType = node.type;
if (nodeType === "BigIntLiteral") {
if (typeof opts === "undefined") {
return true;
} else {
return shallowEqual(node, opts);
}
}
return false;
}
export function isRecordExpression(node: ?Object, opts?: Object): boolean {
if (!node) return false;
@ -3491,17 +3491,17 @@ export function isExpression(node: ?Object, opts?: Object): boolean {
"TaggedTemplateExpression" === nodeType ||
"TemplateLiteral" === nodeType ||
"YieldExpression" === nodeType ||
"AwaitExpression" === nodeType ||
"Import" === nodeType ||
"BigIntLiteral" === nodeType ||
"OptionalMemberExpression" === nodeType ||
"OptionalCallExpression" === nodeType ||
"TypeCastExpression" === nodeType ||
"JSXElement" === nodeType ||
"JSXFragment" === nodeType ||
"AwaitExpression" === nodeType ||
"BindExpression" === nodeType ||
"OptionalMemberExpression" === nodeType ||
"PipelinePrimaryTopicReference" === nodeType ||
"OptionalCallExpression" === nodeType ||
"Import" === nodeType ||
"DoExpression" === nodeType ||
"BigIntLiteral" === nodeType ||
"RecordExpression" === nodeType ||
"TupleExpression" === nodeType ||
"TSAsExpression" === nodeType ||
@ -4063,6 +4063,7 @@ export function isImmutable(node: ?Object, opts?: Object): boolean {
"NumericLiteral" === nodeType ||
"NullLiteral" === nodeType ||
"BooleanLiteral" === nodeType ||
"BigIntLiteral" === nodeType ||
"JSXAttribute" === nodeType ||
"JSXClosingElement" === nodeType ||
"JSXElement" === nodeType ||
@ -4073,7 +4074,6 @@ export function isImmutable(node: ?Object, opts?: Object): boolean {
"JSXFragment" === nodeType ||
"JSXOpeningFragment" === nodeType ||
"JSXClosingFragment" === nodeType ||
"BigIntLiteral" === nodeType ||
(nodeType === "Placeholder" && "StringLiteral" === node.expectedNode)
) {
if (typeof opts === "undefined") {
@ -4269,8 +4269,8 @@ export function isModuleSpecifier(node: ?Object, opts?: Object): boolean {
"ImportDefaultSpecifier" === nodeType ||
"ImportNamespaceSpecifier" === nodeType ||
"ImportSpecifier" === nodeType ||
"ExportDefaultSpecifier" === nodeType ||
"ExportNamespaceSpecifier" === nodeType
"ExportNamespaceSpecifier" === nodeType ||
"ExportDefaultSpecifier" === nodeType
) {
if (typeof opts === "undefined") {
return true;