52d91fdf093f7b6983aee2b14670e4360501b18bfd1886cd1e736ce9293f4e4947d3ff87867d2403f9b4c27e18679235001a22b8d62b37e908600cd07feb6c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.patternLikeCommon = exports.importAttributes = exports.functionTypeAnnotationCommon = exports.functionDeclarationCommon = exports.functionCommon = exports.classMethodOrPropertyCommon = exports.classMethodOrDeclareMethodCommon = void 0;
  6. var _is = require("../validators/is.js");
  7. var _isValidIdentifier = require("../validators/isValidIdentifier.js");
  8. var _helperValidatorIdentifier = require("@babel/helper-validator-identifier");
  9. var _helperStringParser = require("@babel/helper-string-parser");
  10. var _index = require("../constants/index.js");
  11. var _utils = require("./utils.js");
  12. const defineType = (0, _utils.defineAliasedType)("Standardized");
  13. defineType("ArrayExpression", {
  14. fields: {
  15. elements: {
  16. validate: (0, _utils.arrayOf)((0, _utils.assertNodeOrValueType)("null", "Expression", "SpreadElement")),
  17. default: !process.env.BABEL_TYPES_8_BREAKING ? [] : undefined
  18. }
  19. },
  20. visitor: ["elements"],
  21. aliases: ["Expression"]
  22. });
  23. defineType("AssignmentExpression", {
  24. fields: {
  25. operator: {
  26. validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertValueType)("string") : Object.assign(function () {
  27. const identifier = (0, _utils.assertOneOf)(..._index.ASSIGNMENT_OPERATORS);
  28. const pattern = (0, _utils.assertOneOf)("=");
  29. return function (node, key, val) {
  30. const validator = (0, _is.default)("Pattern", node.left) ? pattern : identifier;
  31. validator(node, key, val);
  32. };
  33. }(), {
  34. oneOf: _index.ASSIGNMENT_OPERATORS
  35. })
  36. },
  37. left: {
  38. validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertNodeType)("LVal", "OptionalMemberExpression") : (0, _utils.assertNodeType)("Identifier", "MemberExpression", "OptionalMemberExpression", "ArrayPattern", "ObjectPattern", "TSAsExpression", "TSSatisfiesExpression", "TSTypeAssertion", "TSNonNullExpression")
  39. },
  40. right: {
  41. validate: (0, _utils.assertNodeType)("Expression")
  42. }
  43. },
  44. builder: ["operator", "left", "right"],
  45. visitor: ["left", "right"],
  46. aliases: ["Expression"]
  47. });
  48. defineType("BinaryExpression", {
  49. builder: ["operator", "left", "right"],
  50. fields: {
  51. operator: {
  52. validate: (0, _utils.assertOneOf)(..._index.BINARY_OPERATORS)
  53. },
  54. left: {
  55. validate: function () {
  56. const expression = (0, _utils.assertNodeType)("Expression");
  57. const inOp = (0, _utils.assertNodeType)("Expression", "PrivateName");
  58. const validator = Object.assign(function (node, key, val) {
  59. const validator = node.operator === "in" ? inOp : expression;
  60. validator(node, key, val);
  61. }, {
  62. oneOfNodeTypes: ["Expression", "PrivateName"]
  63. });
  64. return validator;
  65. }()
  66. },
  67. right: {
  68. validate: (0, _utils.assertNodeType)("Expression")
  69. }
  70. },
  71. visitor: ["left", "right"],
  72. aliases: ["Binary", "Expression"]
  73. });
  74. defineType("InterpreterDirective", {
  75. builder: ["value"],
  76. fields: {
  77. value: {
  78. validate: (0, _utils.assertValueType)("string")
  79. }
  80. }
  81. });
  82. defineType("Directive", {
  83. visitor: ["value"],
  84. fields: {
  85. value: {
  86. validate: (0, _utils.assertNodeType)("DirectiveLiteral")
  87. }
  88. }
  89. });
  90. defineType("DirectiveLiteral", {
  91. builder: ["value"],
  92. fields: {
  93. value: {
  94. validate: (0, _utils.assertValueType)("string")
  95. }
  96. }
  97. });
  98. defineType("BlockStatement", {
  99. builder: ["body", "directives"],
  100. visitor: ["directives", "body"],
  101. fields: {
  102. directives: {
  103. validate: (0, _utils.arrayOfType)("Directive"),
  104. default: []
  105. },
  106. body: (0, _utils.validateArrayOfType)("Statement")
  107. },
  108. aliases: ["Scopable", "BlockParent", "Block", "Statement"]
  109. });
  110. defineType("BreakStatement", {
  111. visitor: ["label"],
  112. fields: {
  113. label: {
  114. validate: (0, _utils.assertNodeType)("Identifier"),
  115. optional: true
  116. }
  117. },
  118. aliases: ["Statement", "Terminatorless", "CompletionStatement"]
  119. });
  120. defineType("CallExpression", {
  121. visitor: ["callee", "typeParameters", "typeArguments", "arguments"],
  122. builder: ["callee", "arguments"],
  123. aliases: ["Expression"],
  124. fields: Object.assign({
  125. callee: {
  126. validate: (0, _utils.assertNodeType)("Expression", "Super", "V8IntrinsicIdentifier")
  127. },
  128. arguments: (0, _utils.validateArrayOfType)("Expression", "SpreadElement", "ArgumentPlaceholder"),
  129. typeArguments: {
  130. validate: (0, _utils.assertNodeType)("TypeParameterInstantiation"),
  131. optional: true
  132. }
  133. }, process.env.BABEL_TYPES_8_BREAKING ? {} : {
  134. optional: {
  135. validate: (0, _utils.assertValueType)("boolean"),
  136. optional: true
  137. },
  138. typeParameters: {
  139. validate: (0, _utils.assertNodeType)("TSTypeParameterInstantiation"),
  140. optional: true
  141. }
  142. })
  143. });
  144. defineType("CatchClause", {
  145. visitor: ["param", "body"],
  146. fields: {
  147. param: {
  148. validate: (0, _utils.assertNodeType)("Identifier", "ArrayPattern", "ObjectPattern"),
  149. optional: true
  150. },
  151. body: {
  152. validate: (0, _utils.assertNodeType)("BlockStatement")
  153. }
  154. },
  155. aliases: ["Scopable", "BlockParent"]
  156. });
  157. defineType("ConditionalExpression", {
  158. visitor: ["test", "consequent", "alternate"],
  159. fields: {
  160. test: {
  161. validate: (0, _utils.assertNodeType)("Expression")
  162. },
  163. consequent: {
  164. validate: (0, _utils.assertNodeType)("Expression")
  165. },
  166. alternate: {
  167. validate: (0, _utils.assertNodeType)("Expression")
  168. }
  169. },
  170. aliases: ["Expression", "Conditional"]
  171. });
  172. defineType("ContinueStatement", {
  173. visitor: ["label"],
  174. fields: {
  175. label: {
  176. validate: (0, _utils.assertNodeType)("Identifier"),
  177. optional: true
  178. }
  179. },
  180. aliases: ["Statement", "Terminatorless", "CompletionStatement"]
  181. });
  182. defineType("DebuggerStatement", {
  183. aliases: ["Statement"]
  184. });
  185. defineType("DoWhileStatement", {
  186. builder: ["test", "body"],
  187. visitor: ["body", "test"],
  188. fields: {
  189. test: {
  190. validate: (0, _utils.assertNodeType)("Expression")
  191. },
  192. body: {
  193. validate: (0, _utils.assertNodeType)("Statement")
  194. }
  195. },
  196. aliases: ["Statement", "BlockParent", "Loop", "While", "Scopable"]
  197. });
  198. defineType("EmptyStatement", {
  199. aliases: ["Statement"]
  200. });
  201. defineType("ExpressionStatement", {
  202. visitor: ["expression"],
  203. fields: {
  204. expression: {
  205. validate: (0, _utils.assertNodeType)("Expression")
  206. }
  207. },
  208. aliases: ["Statement", "ExpressionWrapper"]
  209. });
  210. defineType("File", {
  211. builder: ["program", "comments", "tokens"],
  212. visitor: ["program"],
  213. fields: {
  214. program: {
  215. validate: (0, _utils.assertNodeType)("Program")
  216. },
  217. comments: {
  218. validate: !process.env.BABEL_TYPES_8_BREAKING ? Object.assign(() => {}, {
  219. each: {
  220. oneOfNodeTypes: ["CommentBlock", "CommentLine"]
  221. }
  222. }) : (0, _utils.assertEach)((0, _utils.assertNodeType)("CommentBlock", "CommentLine")),
  223. optional: true
  224. },
  225. tokens: {
  226. validate: (0, _utils.assertEach)(Object.assign(() => {}, {
  227. type: "any"
  228. })),
  229. optional: true
  230. }
  231. }
  232. });
  233. defineType("ForInStatement", {
  234. visitor: ["left", "right", "body"],
  235. aliases: ["Scopable", "Statement", "For", "BlockParent", "Loop", "ForXStatement"],
  236. fields: {
  237. left: {
  238. validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertNodeType)("VariableDeclaration", "LVal") : (0, _utils.assertNodeType)("VariableDeclaration", "Identifier", "MemberExpression", "ArrayPattern", "ObjectPattern", "TSAsExpression", "TSSatisfiesExpression", "TSTypeAssertion", "TSNonNullExpression")
  239. },
  240. right: {
  241. validate: (0, _utils.assertNodeType)("Expression")
  242. },
  243. body: {
  244. validate: (0, _utils.assertNodeType)("Statement")
  245. }
  246. }
  247. });
  248. defineType("ForStatement", {
  249. visitor: ["init", "test", "update", "body"],
  250. aliases: ["Scopable", "Statement", "For", "BlockParent", "Loop"],
  251. fields: {
  252. init: {
  253. validate: (0, _utils.assertNodeType)("VariableDeclaration", "Expression"),
  254. optional: true
  255. },
  256. test: {
  257. validate: (0, _utils.assertNodeType)("Expression"),
  258. optional: true
  259. },
  260. update: {
  261. validate: (0, _utils.assertNodeType)("Expression"),
  262. optional: true
  263. },
  264. body: {
  265. validate: (0, _utils.assertNodeType)("Statement")
  266. }
  267. }
  268. });
  269. const functionCommon = () => ({
  270. params: (0, _utils.validateArrayOfType)("FunctionParameter"),
  271. generator: {
  272. default: false
  273. },
  274. async: {
  275. default: false
  276. }
  277. });
  278. exports.functionCommon = functionCommon;
  279. const functionTypeAnnotationCommon = () => ({
  280. returnType: {
  281. validate: (0, _utils.assertNodeType)("TypeAnnotation", "TSTypeAnnotation", "Noop"),
  282. optional: true
  283. },
  284. typeParameters: {
  285. validate: (0, _utils.assertNodeType)("TypeParameterDeclaration", "TSTypeParameterDeclaration", "Noop"),
  286. optional: true
  287. }
  288. });
  289. exports.functionTypeAnnotationCommon = functionTypeAnnotationCommon;
  290. const functionDeclarationCommon = () => Object.assign({}, functionCommon(), {
  291. declare: {
  292. validate: (0, _utils.assertValueType)("boolean"),
  293. optional: true
  294. },
  295. id: {
  296. validate: (0, _utils.assertNodeType)("Identifier"),
  297. optional: true
  298. }
  299. });
  300. exports.functionDeclarationCommon = functionDeclarationCommon;
  301. defineType("FunctionDeclaration", {
  302. builder: ["id", "params", "body", "generator", "async"],
  303. visitor: ["id", "typeParameters", "params", "predicate", "returnType", "body"],
  304. fields: Object.assign({}, functionDeclarationCommon(), functionTypeAnnotationCommon(), {
  305. body: {
  306. validate: (0, _utils.assertNodeType)("BlockStatement")
  307. },
  308. predicate: {
  309. validate: (0, _utils.assertNodeType)("DeclaredPredicate", "InferredPredicate"),
  310. optional: true
  311. }
  312. }),
  313. aliases: ["Scopable", "Function", "BlockParent", "FunctionParent", "Statement", "Pureish", "Declaration"],
  314. validate: !process.env.BABEL_TYPES_8_BREAKING ? undefined : function () {
  315. const identifier = (0, _utils.assertNodeType)("Identifier");
  316. return function (parent, key, node) {
  317. if (!(0, _is.default)("ExportDefaultDeclaration", parent)) {
  318. identifier(node, "id", node.id);
  319. }
  320. };
  321. }()
  322. });
  323. defineType("FunctionExpression", {
  324. inherits: "FunctionDeclaration",
  325. aliases: ["Scopable", "Function", "BlockParent", "FunctionParent", "Expression", "Pureish"],
  326. fields: Object.assign({}, functionCommon(), functionTypeAnnotationCommon(), {
  327. id: {
  328. validate: (0, _utils.assertNodeType)("Identifier"),
  329. optional: true
  330. },
  331. body: {
  332. validate: (0, _utils.assertNodeType)("BlockStatement")
  333. },
  334. predicate: {
  335. validate: (0, _utils.assertNodeType)("DeclaredPredicate", "InferredPredicate"),
  336. optional: true
  337. }
  338. })
  339. });
  340. const patternLikeCommon = () => ({
  341. typeAnnotation: {
  342. validate: (0, _utils.assertNodeType)("TypeAnnotation", "TSTypeAnnotation", "Noop"),
  343. optional: true
  344. },
  345. optional: {
  346. validate: (0, _utils.assertValueType)("boolean"),
  347. optional: true
  348. },
  349. decorators: {
  350. validate: (0, _utils.arrayOfType)("Decorator"),
  351. optional: true
  352. }
  353. });
  354. exports.patternLikeCommon = patternLikeCommon;
  355. defineType("Identifier", {
  356. builder: ["name"],
  357. visitor: ["typeAnnotation", "decorators"],
  358. aliases: ["Expression", "FunctionParameter", "PatternLike", "LVal", "TSEntityName"],
  359. fields: Object.assign({}, patternLikeCommon(), {
  360. name: {
  361. validate: process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.chain)((0, _utils.assertValueType)("string"), Object.assign(function (node, key, val) {
  362. if (!(0, _isValidIdentifier.default)(val, false)) {
  363. throw new TypeError(`"${val}" is not a valid identifier name`);
  364. }
  365. }, {
  366. type: "string"
  367. })) : (0, _utils.assertValueType)("string")
  368. }
  369. }),
  370. validate: process.env.BABEL_TYPES_8_BREAKING ? function (parent, key, node) {
  371. const match = /\.(\w+)$/.exec(key.toString());
  372. if (!match) return;
  373. const [, parentKey] = match;
  374. const nonComp = {
  375. computed: false
  376. };
  377. if (parentKey === "property") {
  378. if ((0, _is.default)("MemberExpression", parent, nonComp)) return;
  379. if ((0, _is.default)("OptionalMemberExpression", parent, nonComp)) return;
  380. } else if (parentKey === "key") {
  381. if ((0, _is.default)("Property", parent, nonComp)) return;
  382. if ((0, _is.default)("Method", parent, nonComp)) return;
  383. } else if (parentKey === "exported") {
  384. if ((0, _is.default)("ExportSpecifier", parent)) return;
  385. } else if (parentKey === "imported") {
  386. if ((0, _is.default)("ImportSpecifier", parent, {
  387. imported: node
  388. })) return;
  389. } else if (parentKey === "meta") {
  390. if ((0, _is.default)("MetaProperty", parent, {
  391. meta: node
  392. })) return;
  393. }
  394. if (((0, _helperValidatorIdentifier.isKeyword)(node.name) || (0, _helperValidatorIdentifier.isReservedWord)(node.name, false)) && node.name !== "this") {
  395. throw new TypeError(`"${node.name}" is not a valid identifier`);
  396. }
  397. } : undefined
  398. });
  399. defineType("IfStatement", {
  400. visitor: ["test", "consequent", "alternate"],
  401. aliases: ["Statement", "Conditional"],
  402. fields: {
  403. test: {
  404. validate: (0, _utils.assertNodeType)("Expression")
  405. },
  406. consequent: {
  407. validate: (0, _utils.assertNodeType)("Statement")
  408. },
  409. alternate: {
  410. optional: true,
  411. validate: (0, _utils.assertNodeType)("Statement")
  412. }
  413. }
  414. });
  415. defineType("LabeledStatement", {
  416. visitor: ["label", "body"],
  417. aliases: ["Statement"],
  418. fields: {
  419. label: {
  420. validate: (0, _utils.assertNodeType)("Identifier")
  421. },
  422. body: {
  423. validate: (0, _utils.assertNodeType)("Statement")
  424. }
  425. }
  426. });
  427. defineType("StringLiteral", {
  428. builder: ["value"],
  429. fields: {
  430. value: {
  431. validate: (0, _utils.assertValueType)("string")
  432. }
  433. },
  434. aliases: ["Expression", "Pureish", "Literal", "Immutable"]
  435. });
  436. defineType("NumericLiteral", {
  437. builder: ["value"],
  438. deprecatedAlias: "NumberLiteral",
  439. fields: {
  440. value: {
  441. validate: (0, _utils.chain)((0, _utils.assertValueType)("number"), Object.assign(function (node, key, val) {
  442. if (1 / val < 0 || !Number.isFinite(val)) {
  443. const error = new Error("NumericLiterals must be non-negative finite numbers. " + `You can use t.valueToNode(${val}) instead.`);
  444. {}
  445. }
  446. }, {
  447. type: "number"
  448. }))
  449. }
  450. },
  451. aliases: ["Expression", "Pureish", "Literal", "Immutable"]
  452. });
  453. defineType("NullLiteral", {
  454. aliases: ["Expression", "Pureish", "Literal", "Immutable"]
  455. });
  456. defineType("BooleanLiteral", {
  457. builder: ["value"],
  458. fields: {
  459. value: {
  460. validate: (0, _utils.assertValueType)("boolean")
  461. }
  462. },
  463. aliases: ["Expression", "Pureish", "Literal", "Immutable"]
  464. });
  465. defineType("RegExpLiteral", {
  466. builder: ["pattern", "flags"],
  467. deprecatedAlias: "RegexLiteral",
  468. aliases: ["Expression", "Pureish", "Literal"],
  469. fields: {
  470. pattern: {
  471. validate: (0, _utils.assertValueType)("string")
  472. },
  473. flags: {
  474. validate: process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.chain)((0, _utils.assertValueType)("string"), Object.assign(function (node, key, val) {
  475. const invalid = /[^dgimsuvy]/.exec(val);
  476. if (invalid) {
  477. throw new TypeError(`"${invalid[0]}" is not a valid RegExp flag`);
  478. }
  479. }, {
  480. type: "string"
  481. })) : (0, _utils.assertValueType)("string"),
  482. default: ""
  483. }
  484. }
  485. });
  486. defineType("LogicalExpression", {
  487. builder: ["operator", "left", "right"],
  488. visitor: ["left", "right"],
  489. aliases: ["Binary", "Expression"],
  490. fields: {
  491. operator: {
  492. validate: (0, _utils.assertOneOf)(..._index.LOGICAL_OPERATORS)
  493. },
  494. left: {
  495. validate: (0, _utils.assertNodeType)("Expression")
  496. },
  497. right: {
  498. validate: (0, _utils.assertNodeType)("Expression")
  499. }
  500. }
  501. });
  502. defineType("MemberExpression", {
  503. builder: ["object", "property", "computed", ...(!process.env.BABEL_TYPES_8_BREAKING ? ["optional"] : [])],
  504. visitor: ["object", "property"],
  505. aliases: ["Expression", "LVal", "PatternLike"],
  506. fields: Object.assign({
  507. object: {
  508. validate: (0, _utils.assertNodeType)("Expression", "Super")
  509. },
  510. property: {
  511. validate: function () {
  512. const normal = (0, _utils.assertNodeType)("Identifier", "PrivateName");
  513. const computed = (0, _utils.assertNodeType)("Expression");
  514. const validator = function (node, key, val) {
  515. const validator = node.computed ? computed : normal;
  516. validator(node, key, val);
  517. };
  518. validator.oneOfNodeTypes = ["Expression", "Identifier", "PrivateName"];
  519. return validator;
  520. }()
  521. },
  522. computed: {
  523. default: false
  524. }
  525. }, !process.env.BABEL_TYPES_8_BREAKING ? {
  526. optional: {
  527. validate: (0, _utils.assertValueType)("boolean"),
  528. optional: true
  529. }
  530. } : {})
  531. });
  532. defineType("NewExpression", {
  533. inherits: "CallExpression"
  534. });
  535. defineType("Program", {
  536. visitor: ["directives", "body"],
  537. builder: ["body", "directives", "sourceType", "interpreter"],
  538. fields: {
  539. sourceType: {
  540. validate: (0, _utils.assertOneOf)("script", "module"),
  541. default: "script"
  542. },
  543. interpreter: {
  544. validate: (0, _utils.assertNodeType)("InterpreterDirective"),
  545. default: null,
  546. optional: true
  547. },
  548. directives: {
  549. validate: (0, _utils.arrayOfType)("Directive"),
  550. default: []
  551. },
  552. body: (0, _utils.validateArrayOfType)("Statement")
  553. },
  554. aliases: ["Scopable", "BlockParent", "Block"]
  555. });
  556. defineType("ObjectExpression", {
  557. visitor: ["properties"],
  558. aliases: ["Expression"],
  559. fields: {
  560. properties: (0, _utils.validateArrayOfType)("ObjectMethod", "ObjectProperty", "SpreadElement")
  561. }
  562. });
  563. defineType("ObjectMethod", {
  564. builder: ["kind", "key", "params", "body", "computed", "generator", "async"],
  565. visitor: ["decorators", "key", "typeParameters", "params", "returnType", "body"],
  566. fields: Object.assign({}, functionCommon(), functionTypeAnnotationCommon(), {
  567. kind: Object.assign({
  568. validate: (0, _utils.assertOneOf)("method", "get", "set")
  569. }, !process.env.BABEL_TYPES_8_BREAKING ? {
  570. default: "method"
  571. } : {}),
  572. computed: {
  573. default: false
  574. },
  575. key: {
  576. validate: function () {
  577. const normal = (0, _utils.assertNodeType)("Identifier", "StringLiteral", "NumericLiteral", "BigIntLiteral");
  578. const computed = (0, _utils.assertNodeType)("Expression");
  579. const validator = function (node, key, val) {
  580. const validator = node.computed ? computed : normal;
  581. validator(node, key, val);
  582. };
  583. validator.oneOfNodeTypes = ["Expression", "Identifier", "StringLiteral", "NumericLiteral", "BigIntLiteral"];
  584. return validator;
  585. }()
  586. },
  587. decorators: {
  588. validate: (0, _utils.arrayOfType)("Decorator"),
  589. optional: true
  590. },
  591. body: {
  592. validate: (0, _utils.assertNodeType)("BlockStatement")
  593. }
  594. }),
  595. aliases: ["UserWhitespacable", "Function", "Scopable", "BlockParent", "FunctionParent", "Method", "ObjectMember"]
  596. });
  597. defineType("ObjectProperty", {
  598. builder: ["key", "value", "computed", "shorthand", ...(!process.env.BABEL_TYPES_8_BREAKING ? ["decorators"] : [])],
  599. fields: {
  600. computed: {
  601. default: false
  602. },
  603. key: {
  604. validate: function () {
  605. const normal = (0, _utils.assertNodeType)("Identifier", "StringLiteral", "NumericLiteral", "BigIntLiteral", "DecimalLiteral", "PrivateName");
  606. const computed = (0, _utils.assertNodeType)("Expression");
  607. const validator = Object.assign(function (node, key, val) {
  608. const validator = node.computed ? computed : normal;
  609. validator(node, key, val);
  610. }, {
  611. oneOfNodeTypes: ["Expression", "Identifier", "StringLiteral", "NumericLiteral", "BigIntLiteral", "DecimalLiteral", "PrivateName"]
  612. });
  613. return validator;
  614. }()
  615. },
  616. value: {
  617. validate: (0, _utils.assertNodeType)("Expression", "PatternLike")
  618. },
  619. shorthand: {
  620. validate: process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.chain)((0, _utils.assertValueType)("boolean"), Object.assign(function (node, key, shorthand) {
  621. if (!shorthand) return;
  622. if (node.computed) {
  623. throw new TypeError("Property shorthand of ObjectProperty cannot be true if computed is true");
  624. }
  625. if (!(0, _is.default)("Identifier", node.key)) {
  626. throw new TypeError("Property shorthand of ObjectProperty cannot be true if key is not an Identifier");
  627. }
  628. }, {
  629. type: "boolean"
  630. })) : (0, _utils.assertValueType)("boolean"),
  631. default: false
  632. },
  633. decorators: {
  634. validate: (0, _utils.arrayOfType)("Decorator"),
  635. optional: true
  636. }
  637. },
  638. visitor: ["decorators", "key", "value"],
  639. aliases: ["UserWhitespacable", "Property", "ObjectMember"],
  640. validate: !process.env.BABEL_TYPES_8_BREAKING ? undefined : function () {
  641. const pattern = (0, _utils.assertNodeType)("Identifier", "Pattern", "TSAsExpression", "TSSatisfiesExpression", "TSNonNullExpression", "TSTypeAssertion");
  642. const expression = (0, _utils.assertNodeType)("Expression");
  643. return function (parent, key, node) {
  644. const validator = (0, _is.default)("ObjectPattern", parent) ? pattern : expression;
  645. validator(node, "value", node.value);
  646. };
  647. }()
  648. });
  649. defineType("RestElement", {
  650. visitor: ["argument", "typeAnnotation"],
  651. builder: ["argument"],
  652. aliases: ["FunctionParameter", "PatternLike", "LVal"],
  653. deprecatedAlias: "RestProperty",
  654. fields: Object.assign({}, patternLikeCommon(), {
  655. argument: {
  656. validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertNodeType)("Identifier", "ArrayPattern", "ObjectPattern", "MemberExpression", "TSAsExpression", "TSSatisfiesExpression", "TSTypeAssertion", "TSNonNullExpression", "RestElement", "AssignmentPattern") : (0, _utils.assertNodeType)("Identifier", "ArrayPattern", "ObjectPattern", "MemberExpression", "TSAsExpression", "TSSatisfiesExpression", "TSTypeAssertion", "TSNonNullExpression")
  657. }
  658. }),
  659. validate: process.env.BABEL_TYPES_8_BREAKING ? function (parent, key) {
  660. const match = /(\w+)\[(\d+)\]/.exec(key.toString());
  661. if (!match) throw new Error("Internal Babel error: malformed key.");
  662. const [, listKey, index] = match;
  663. if (parent[listKey].length > +index + 1) {
  664. throw new TypeError(`RestElement must be last element of ${listKey}`);
  665. }
  666. } : undefined
  667. });
  668. defineType("ReturnStatement", {
  669. visitor: ["argument"],
  670. aliases: ["Statement", "Terminatorless", "CompletionStatement"],
  671. fields: {
  672. argument: {
  673. validate: (0, _utils.assertNodeType)("Expression"),
  674. optional: true
  675. }
  676. }
  677. });
  678. defineType("SequenceExpression", {
  679. visitor: ["expressions"],
  680. fields: {
  681. expressions: (0, _utils.validateArrayOfType)("Expression")
  682. },
  683. aliases: ["Expression"]
  684. });
  685. defineType("ParenthesizedExpression", {
  686. visitor: ["expression"],
  687. aliases: ["Expression", "ExpressionWrapper"],
  688. fields: {
  689. expression: {
  690. validate: (0, _utils.assertNodeType)("Expression")
  691. }
  692. }
  693. });
  694. defineType("SwitchCase", {
  695. visitor: ["test", "consequent"],
  696. fields: {
  697. test: {
  698. validate: (0, _utils.assertNodeType)("Expression"),
  699. optional: true
  700. },
  701. consequent: (0, _utils.validateArrayOfType)("Statement")
  702. }
  703. });
  704. defineType("SwitchStatement", {
  705. visitor: ["discriminant", "cases"],
  706. aliases: ["Statement", "BlockParent", "Scopable"],
  707. fields: {
  708. discriminant: {
  709. validate: (0, _utils.assertNodeType)("Expression")
  710. },
  711. cases: (0, _utils.validateArrayOfType)("SwitchCase")
  712. }
  713. });
  714. defineType("ThisExpression", {
  715. aliases: ["Expression"]
  716. });
  717. defineType("ThrowStatement", {
  718. visitor: ["argument"],
  719. aliases: ["Statement", "Terminatorless", "CompletionStatement"],
  720. fields: {
  721. argument: {
  722. validate: (0, _utils.assertNodeType)("Expression")
  723. }
  724. }
  725. });
  726. defineType("TryStatement", {
  727. visitor: ["block", "handler", "finalizer"],
  728. aliases: ["Statement"],
  729. fields: {
  730. block: {
  731. validate: process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.chain)((0, _utils.assertNodeType)("BlockStatement"), Object.assign(function (node) {
  732. if (!node.handler && !node.finalizer) {
  733. throw new TypeError("TryStatement expects either a handler or finalizer, or both");
  734. }
  735. }, {
  736. oneOfNodeTypes: ["BlockStatement"]
  737. })) : (0, _utils.assertNodeType)("BlockStatement")
  738. },
  739. handler: {
  740. optional: true,
  741. validate: (0, _utils.assertNodeType)("CatchClause")
  742. },
  743. finalizer: {
  744. optional: true,
  745. validate: (0, _utils.assertNodeType)("BlockStatement")
  746. }
  747. }
  748. });
  749. defineType("UnaryExpression", {
  750. builder: ["operator", "argument", "prefix"],
  751. fields: {
  752. prefix: {
  753. default: true
  754. },
  755. argument: {
  756. validate: (0, _utils.assertNodeType)("Expression")
  757. },
  758. operator: {
  759. validate: (0, _utils.assertOneOf)(..._index.UNARY_OPERATORS)
  760. }
  761. },
  762. visitor: ["argument"],
  763. aliases: ["UnaryLike", "Expression"]
  764. });
  765. defineType("UpdateExpression", {
  766. builder: ["operator", "argument", "prefix"],
  767. fields: {
  768. prefix: {
  769. default: false
  770. },
  771. argument: {
  772. validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertNodeType)("Expression") : (0, _utils.assertNodeType)("Identifier", "MemberExpression")
  773. },
  774. operator: {
  775. validate: (0, _utils.assertOneOf)(..._index.UPDATE_OPERATORS)
  776. }
  777. },
  778. visitor: ["argument"],
  779. aliases: ["Expression"]
  780. });
  781. defineType("VariableDeclaration", {
  782. builder: ["kind", "declarations"],
  783. visitor: ["declarations"],
  784. aliases: ["Statement", "Declaration"],
  785. fields: {
  786. declare: {
  787. validate: (0, _utils.assertValueType)("boolean"),
  788. optional: true
  789. },
  790. kind: {
  791. validate: (0, _utils.assertOneOf)("var", "let", "const", "using", "await using")
  792. },
  793. declarations: (0, _utils.validateArrayOfType)("VariableDeclarator")
  794. },
  795. validate: process.env.BABEL_TYPES_8_BREAKING ? (() => {
  796. const withoutInit = (0, _utils.assertNodeType)("Identifier", "Placeholder");
  797. const constOrLetOrVar = (0, _utils.assertNodeType)("Identifier", "ArrayPattern", "ObjectPattern", "Placeholder");
  798. const usingOrAwaitUsing = (0, _utils.assertNodeType)("Identifier", "VoidPattern", "Placeholder");
  799. return function (parent, key, node) {
  800. const {
  801. kind,
  802. declarations
  803. } = node;
  804. const parentIsForX = (0, _is.default)("ForXStatement", parent, {
  805. left: node
  806. });
  807. if (parentIsForX) {
  808. if (declarations.length !== 1) {
  809. throw new TypeError(`Exactly one VariableDeclarator is required in the VariableDeclaration of a ${parent.type}`);
  810. }
  811. }
  812. for (const decl of declarations) {
  813. if (kind === "const" || kind === "let" || kind === "var") {
  814. if (!parentIsForX && !decl.init) {
  815. withoutInit(decl, "id", decl.id);
  816. } else {
  817. constOrLetOrVar(decl, "id", decl.id);
  818. }
  819. } else {
  820. usingOrAwaitUsing(decl, "id", decl.id);
  821. }
  822. }
  823. };
  824. })() : undefined
  825. });
  826. defineType("VariableDeclarator", {
  827. visitor: ["id", "init"],
  828. fields: {
  829. id: {
  830. validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertNodeType)("LVal", "VoidPattern") : (0, _utils.assertNodeType)("Identifier", "ArrayPattern", "ObjectPattern", "VoidPattern")
  831. },
  832. definite: {
  833. optional: true,
  834. validate: (0, _utils.assertValueType)("boolean")
  835. },
  836. init: {
  837. optional: true,
  838. validate: (0, _utils.assertNodeType)("Expression")
  839. }
  840. }
  841. });
  842. defineType("WhileStatement", {
  843. visitor: ["test", "body"],
  844. aliases: ["Statement", "BlockParent", "Loop", "While", "Scopable"],
  845. fields: {
  846. test: {
  847. validate: (0, _utils.assertNodeType)("Expression")
  848. },
  849. body: {
  850. validate: (0, _utils.assertNodeType)("Statement")
  851. }
  852. }
  853. });
  854. defineType("WithStatement", {
  855. visitor: ["object", "body"],
  856. aliases: ["Statement"],
  857. fields: {
  858. object: {
  859. validate: (0, _utils.assertNodeType)("Expression")
  860. },
  861. body: {
  862. validate: (0, _utils.assertNodeType)("Statement")
  863. }
  864. }
  865. });
  866. defineType("AssignmentPattern", {
  867. visitor: ["left", "right", "decorators"],
  868. builder: ["left", "right"],
  869. aliases: ["FunctionParameter", "Pattern", "PatternLike", "LVal"],
  870. fields: Object.assign({}, patternLikeCommon(), {
  871. left: {
  872. validate: (0, _utils.assertNodeType)("Identifier", "ObjectPattern", "ArrayPattern", "MemberExpression", "TSAsExpression", "TSSatisfiesExpression", "TSTypeAssertion", "TSNonNullExpression")
  873. },
  874. right: {
  875. validate: (0, _utils.assertNodeType)("Expression")
  876. },
  877. decorators: {
  878. validate: (0, _utils.arrayOfType)("Decorator"),
  879. optional: true
  880. }
  881. })
  882. });
  883. defineType("ArrayPattern", {
  884. visitor: ["elements", "typeAnnotation"],
  885. builder: ["elements"],
  886. aliases: ["FunctionParameter", "Pattern", "PatternLike", "LVal"],
  887. fields: Object.assign({}, patternLikeCommon(), {
  888. elements: {
  889. validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeOrValueType)("null", "PatternLike")))
  890. }
  891. })
  892. });
  893. defineType("ArrowFunctionExpression", {
  894. builder: ["params", "body", "async"],
  895. visitor: ["typeParameters", "params", "predicate", "returnType", "body"],
  896. aliases: ["Scopable", "Function", "BlockParent", "FunctionParent", "Expression", "Pureish"],
  897. fields: Object.assign({}, functionCommon(), functionTypeAnnotationCommon(), {
  898. expression: {
  899. validate: (0, _utils.assertValueType)("boolean")
  900. },
  901. body: {
  902. validate: (0, _utils.assertNodeType)("BlockStatement", "Expression")
  903. },
  904. predicate: {
  905. validate: (0, _utils.assertNodeType)("DeclaredPredicate", "InferredPredicate"),
  906. optional: true
  907. }
  908. })
  909. });
  910. defineType("ClassBody", {
  911. visitor: ["body"],
  912. fields: {
  913. body: (0, _utils.validateArrayOfType)("ClassMethod", "ClassPrivateMethod", "ClassProperty", "ClassPrivateProperty", "ClassAccessorProperty", "TSDeclareMethod", "TSIndexSignature", "StaticBlock")
  914. }
  915. });
  916. defineType("ClassExpression", {
  917. builder: ["id", "superClass", "body", "decorators"],
  918. visitor: ["decorators", "id", "typeParameters", "superClass", "superTypeParameters", "mixins", "implements", "body"],
  919. aliases: ["Scopable", "Class", "Expression"],
  920. fields: {
  921. id: {
  922. validate: (0, _utils.assertNodeType)("Identifier"),
  923. optional: true
  924. },
  925. typeParameters: {
  926. validate: (0, _utils.assertNodeType)("TypeParameterDeclaration", "TSTypeParameterDeclaration", "Noop"),
  927. optional: true
  928. },
  929. body: {
  930. validate: (0, _utils.assertNodeType)("ClassBody")
  931. },
  932. superClass: {
  933. optional: true,
  934. validate: (0, _utils.assertNodeType)("Expression")
  935. },
  936. ["superTypeParameters"]: {
  937. validate: (0, _utils.assertNodeType)("TypeParameterInstantiation", "TSTypeParameterInstantiation"),
  938. optional: true
  939. },
  940. implements: {
  941. validate: (0, _utils.arrayOfType)("TSExpressionWithTypeArguments", "ClassImplements"),
  942. optional: true
  943. },
  944. decorators: {
  945. validate: (0, _utils.arrayOfType)("Decorator"),
  946. optional: true
  947. },
  948. mixins: {
  949. validate: (0, _utils.assertNodeType)("InterfaceExtends"),
  950. optional: true
  951. }
  952. }
  953. });
  954. defineType("ClassDeclaration", {
  955. inherits: "ClassExpression",
  956. aliases: ["Scopable", "Class", "Statement", "Declaration"],
  957. fields: {
  958. id: {
  959. validate: (0, _utils.assertNodeType)("Identifier"),
  960. optional: true
  961. },
  962. typeParameters: {
  963. validate: (0, _utils.assertNodeType)("TypeParameterDeclaration", "TSTypeParameterDeclaration", "Noop"),
  964. optional: true
  965. },
  966. body: {
  967. validate: (0, _utils.assertNodeType)("ClassBody")
  968. },
  969. superClass: {
  970. optional: true,
  971. validate: (0, _utils.assertNodeType)("Expression")
  972. },
  973. ["superTypeParameters"]: {
  974. validate: (0, _utils.assertNodeType)("TypeParameterInstantiation", "TSTypeParameterInstantiation"),
  975. optional: true
  976. },
  977. implements: {
  978. validate: (0, _utils.arrayOfType)("TSExpressionWithTypeArguments", "ClassImplements"),
  979. optional: true
  980. },
  981. decorators: {
  982. validate: (0, _utils.arrayOfType)("Decorator"),
  983. optional: true
  984. },
  985. mixins: {
  986. validate: (0, _utils.assertNodeType)("InterfaceExtends"),
  987. optional: true
  988. },
  989. declare: {
  990. validate: (0, _utils.assertValueType)("boolean"),
  991. optional: true
  992. },
  993. abstract: {
  994. validate: (0, _utils.assertValueType)("boolean"),
  995. optional: true
  996. }
  997. },
  998. validate: !process.env.BABEL_TYPES_8_BREAKING ? undefined : function () {
  999. const identifier = (0, _utils.assertNodeType)("Identifier");
  1000. return function (parent, key, node) {
  1001. if (!(0, _is.default)("ExportDefaultDeclaration", parent)) {
  1002. identifier(node, "id", node.id);
  1003. }
  1004. };
  1005. }()
  1006. });
  1007. const importAttributes = exports.importAttributes = {
  1008. attributes: {
  1009. optional: true,
  1010. validate: (0, _utils.arrayOfType)("ImportAttribute")
  1011. },
  1012. assertions: {
  1013. deprecated: true,
  1014. optional: true,
  1015. validate: (0, _utils.arrayOfType)("ImportAttribute")
  1016. }
  1017. };
  1018. defineType("ExportAllDeclaration", {
  1019. builder: ["source"],
  1020. visitor: ["source", "attributes", "assertions"],
  1021. aliases: ["Statement", "Declaration", "ImportOrExportDeclaration", "ExportDeclaration"],
  1022. fields: Object.assign({
  1023. source: {
  1024. validate: (0, _utils.assertNodeType)("StringLiteral")
  1025. },
  1026. exportKind: (0, _utils.validateOptional)((0, _utils.assertOneOf)("type", "value"))
  1027. }, importAttributes)
  1028. });
  1029. defineType("ExportDefaultDeclaration", {
  1030. visitor: ["declaration"],
  1031. aliases: ["Statement", "Declaration", "ImportOrExportDeclaration", "ExportDeclaration"],
  1032. fields: {
  1033. declaration: (0, _utils.validateType)("TSDeclareFunction", "FunctionDeclaration", "ClassDeclaration", "Expression"),
  1034. exportKind: (0, _utils.validateOptional)((0, _utils.assertOneOf)("value"))
  1035. }
  1036. });
  1037. defineType("ExportNamedDeclaration", {
  1038. builder: ["declaration", "specifiers", "source"],
  1039. visitor: ["declaration", "specifiers", "source", "attributes", "assertions"],
  1040. aliases: ["Statement", "Declaration", "ImportOrExportDeclaration", "ExportDeclaration"],
  1041. fields: Object.assign({
  1042. declaration: {
  1043. optional: true,
  1044. validate: process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.chain)((0, _utils.assertNodeType)("Declaration"), Object.assign(function (node, key, val) {
  1045. if (val && node.specifiers.length) {
  1046. throw new TypeError("Only declaration or specifiers is allowed on ExportNamedDeclaration");
  1047. }
  1048. if (val && node.source) {
  1049. throw new TypeError("Cannot export a declaration from a source");
  1050. }
  1051. }, {
  1052. oneOfNodeTypes: ["Declaration"]
  1053. })) : (0, _utils.assertNodeType)("Declaration")
  1054. }
  1055. }, importAttributes, {
  1056. specifiers: {
  1057. default: [],
  1058. validate: (0, _utils.arrayOf)(function () {
  1059. const sourced = (0, _utils.assertNodeType)("ExportSpecifier", "ExportDefaultSpecifier", "ExportNamespaceSpecifier");
  1060. const sourceless = (0, _utils.assertNodeType)("ExportSpecifier");
  1061. if (!process.env.BABEL_TYPES_8_BREAKING) return sourced;
  1062. return Object.assign(function (node, key, val) {
  1063. const validator = node.source ? sourced : sourceless;
  1064. validator(node, key, val);
  1065. }, {
  1066. oneOfNodeTypes: ["ExportSpecifier", "ExportDefaultSpecifier", "ExportNamespaceSpecifier"]
  1067. });
  1068. }())
  1069. },
  1070. source: {
  1071. validate: (0, _utils.assertNodeType)("StringLiteral"),
  1072. optional: true
  1073. },
  1074. exportKind: (0, _utils.validateOptional)((0, _utils.assertOneOf)("type", "value"))
  1075. })
  1076. });
  1077. defineType("ExportSpecifier", {
  1078. visitor: ["local", "exported"],
  1079. aliases: ["ModuleSpecifier"],
  1080. fields: {
  1081. local: {
  1082. validate: (0, _utils.assertNodeType)("Identifier")
  1083. },
  1084. exported: {
  1085. validate: (0, _utils.assertNodeType)("Identifier", "StringLiteral")
  1086. },
  1087. exportKind: {
  1088. validate: (0, _utils.assertOneOf)("type", "value"),
  1089. optional: true
  1090. }
  1091. }
  1092. });
  1093. defineType("ForOfStatement", {
  1094. visitor: ["left", "right", "body"],
  1095. builder: ["left", "right", "body", "await"],
  1096. aliases: ["Scopable", "Statement", "For", "BlockParent", "Loop", "ForXStatement"],
  1097. fields: {
  1098. left: {
  1099. validate: function () {
  1100. if (!process.env.BABEL_TYPES_8_BREAKING) {
  1101. return (0, _utils.assertNodeType)("VariableDeclaration", "LVal");
  1102. }
  1103. const declaration = (0, _utils.assertNodeType)("VariableDeclaration");
  1104. const lval = (0, _utils.assertNodeType)("Identifier", "MemberExpression", "ArrayPattern", "ObjectPattern", "TSAsExpression", "TSSatisfiesExpression", "TSTypeAssertion", "TSNonNullExpression");
  1105. return Object.assign(function (node, key, val) {
  1106. if ((0, _is.default)("VariableDeclaration", val)) {
  1107. declaration(node, key, val);
  1108. } else {
  1109. lval(node, key, val);
  1110. }
  1111. }, {
  1112. oneOfNodeTypes: ["VariableDeclaration", "Identifier", "MemberExpression", "ArrayPattern", "ObjectPattern", "TSAsExpression", "TSSatisfiesExpression", "TSTypeAssertion", "TSNonNullExpression"]
  1113. });
  1114. }()
  1115. },
  1116. right: {
  1117. validate: (0, _utils.assertNodeType)("Expression")
  1118. },
  1119. body: {
  1120. validate: (0, _utils.assertNodeType)("Statement")
  1121. },
  1122. await: {
  1123. default: false
  1124. }
  1125. }
  1126. });
  1127. defineType("ImportDeclaration", {
  1128. builder: ["specifiers", "source"],
  1129. visitor: ["specifiers", "source", "attributes", "assertions"],
  1130. aliases: ["Statement", "Declaration", "ImportOrExportDeclaration"],
  1131. fields: Object.assign({}, importAttributes, {
  1132. module: {
  1133. optional: true,
  1134. validate: (0, _utils.assertValueType)("boolean")
  1135. },
  1136. phase: {
  1137. default: null,
  1138. validate: (0, _utils.assertOneOf)("source", "defer")
  1139. },
  1140. specifiers: (0, _utils.validateArrayOfType)("ImportSpecifier", "ImportDefaultSpecifier", "ImportNamespaceSpecifier"),
  1141. source: {
  1142. validate: (0, _utils.assertNodeType)("StringLiteral")
  1143. },
  1144. importKind: {
  1145. validate: (0, _utils.assertOneOf)("type", "typeof", "value"),
  1146. optional: true
  1147. }
  1148. })
  1149. });
  1150. defineType("ImportDefaultSpecifier", {
  1151. visitor: ["local"],
  1152. aliases: ["ModuleSpecifier"],
  1153. fields: {
  1154. local: {
  1155. validate: (0, _utils.assertNodeType)("Identifier")
  1156. }
  1157. }
  1158. });
  1159. defineType("ImportNamespaceSpecifier", {
  1160. visitor: ["local"],
  1161. aliases: ["ModuleSpecifier"],
  1162. fields: {
  1163. local: {
  1164. validate: (0, _utils.assertNodeType)("Identifier")
  1165. }
  1166. }
  1167. });
  1168. defineType("ImportSpecifier", {
  1169. visitor: ["imported", "local"],
  1170. builder: ["local", "imported"],
  1171. aliases: ["ModuleSpecifier"],
  1172. fields: {
  1173. local: {
  1174. validate: (0, _utils.assertNodeType)("Identifier")
  1175. },
  1176. imported: {
  1177. validate: (0, _utils.assertNodeType)("Identifier", "StringLiteral")
  1178. },
  1179. importKind: {
  1180. validate: (0, _utils.assertOneOf)("type", "typeof", "value"),
  1181. optional: true
  1182. }
  1183. }
  1184. });
  1185. defineType("ImportExpression", {
  1186. visitor: ["source", "options"],
  1187. aliases: ["Expression"],
  1188. fields: {
  1189. phase: {
  1190. default: null,
  1191. validate: (0, _utils.assertOneOf)("source", "defer")
  1192. },
  1193. source: {
  1194. validate: (0, _utils.assertNodeType)("Expression")
  1195. },
  1196. options: {
  1197. validate: (0, _utils.assertNodeType)("Expression"),
  1198. optional: true
  1199. }
  1200. }
  1201. });
  1202. defineType("MetaProperty", {
  1203. visitor: ["meta", "property"],
  1204. aliases: ["Expression"],
  1205. fields: {
  1206. meta: {
  1207. validate: process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.chain)((0, _utils.assertNodeType)("Identifier"), Object.assign(function (node, key, val) {
  1208. let property;
  1209. switch (val.name) {
  1210. case "function":
  1211. property = "sent";
  1212. break;
  1213. case "new":
  1214. property = "target";
  1215. break;
  1216. case "import":
  1217. property = "meta";
  1218. break;
  1219. }
  1220. if (!(0, _is.default)("Identifier", node.property, {
  1221. name: property
  1222. })) {
  1223. throw new TypeError("Unrecognised MetaProperty");
  1224. }
  1225. }, {
  1226. oneOfNodeTypes: ["Identifier"]
  1227. })) : (0, _utils.assertNodeType)("Identifier")
  1228. },
  1229. property: {
  1230. validate: (0, _utils.assertNodeType)("Identifier")
  1231. }
  1232. }
  1233. });
  1234. const classMethodOrPropertyCommon = () => ({
  1235. abstract: {
  1236. validate: (0, _utils.assertValueType)("boolean"),
  1237. optional: true
  1238. },
  1239. accessibility: {
  1240. validate: (0, _utils.assertOneOf)("public", "private", "protected"),
  1241. optional: true
  1242. },
  1243. static: {
  1244. default: false
  1245. },
  1246. override: {
  1247. default: false
  1248. },
  1249. computed: {
  1250. default: false
  1251. },
  1252. optional: {
  1253. validate: (0, _utils.assertValueType)("boolean"),
  1254. optional: true
  1255. },
  1256. key: {
  1257. validate: (0, _utils.chain)(function () {
  1258. const normal = (0, _utils.assertNodeType)("Identifier", "StringLiteral", "NumericLiteral", "BigIntLiteral");
  1259. const computed = (0, _utils.assertNodeType)("Expression");
  1260. return function (node, key, val) {
  1261. const validator = node.computed ? computed : normal;
  1262. validator(node, key, val);
  1263. };
  1264. }(), (0, _utils.assertNodeType)("Identifier", "StringLiteral", "NumericLiteral", "BigIntLiteral", "Expression"))
  1265. }
  1266. });
  1267. exports.classMethodOrPropertyCommon = classMethodOrPropertyCommon;
  1268. const classMethodOrDeclareMethodCommon = () => Object.assign({}, functionCommon(), classMethodOrPropertyCommon(), {
  1269. params: (0, _utils.validateArrayOfType)("FunctionParameter", "TSParameterProperty"),
  1270. kind: {
  1271. validate: (0, _utils.assertOneOf)("get", "set", "method", "constructor"),
  1272. default: "method"
  1273. },
  1274. access: {
  1275. validate: (0, _utils.chain)((0, _utils.assertValueType)("string"), (0, _utils.assertOneOf)("public", "private", "protected")),
  1276. optional: true
  1277. },
  1278. decorators: {
  1279. validate: (0, _utils.arrayOfType)("Decorator"),
  1280. optional: true
  1281. }
  1282. });
  1283. exports.classMethodOrDeclareMethodCommon = classMethodOrDeclareMethodCommon;
  1284. defineType("ClassMethod", {
  1285. aliases: ["Function", "Scopable", "BlockParent", "FunctionParent", "Method"],
  1286. builder: ["kind", "key", "params", "body", "computed", "static", "generator", "async"],
  1287. visitor: ["decorators", "key", "typeParameters", "params", "returnType", "body"],
  1288. fields: Object.assign({}, classMethodOrDeclareMethodCommon(), functionTypeAnnotationCommon(), {
  1289. body: {
  1290. validate: (0, _utils.assertNodeType)("BlockStatement")
  1291. }
  1292. })
  1293. });
  1294. defineType("ObjectPattern", {
  1295. visitor: ["decorators", "properties", "typeAnnotation"],
  1296. builder: ["properties"],
  1297. aliases: ["FunctionParameter", "Pattern", "PatternLike", "LVal"],
  1298. fields: Object.assign({}, patternLikeCommon(), {
  1299. properties: (0, _utils.validateArrayOfType)("RestElement", "ObjectProperty")
  1300. })
  1301. });
  1302. defineType("SpreadElement", {
  1303. visitor: ["argument"],
  1304. aliases: ["UnaryLike"],
  1305. deprecatedAlias: "SpreadProperty",
  1306. fields: {
  1307. argument: {
  1308. validate: (0, _utils.assertNodeType)("Expression")
  1309. }
  1310. }
  1311. });
  1312. defineType("Super", {
  1313. aliases: ["Expression"]
  1314. });
  1315. defineType("TaggedTemplateExpression", {
  1316. visitor: ["tag", "typeParameters", "quasi"],
  1317. builder: ["tag", "quasi"],
  1318. aliases: ["Expression"],
  1319. fields: {
  1320. tag: {
  1321. validate: (0, _utils.assertNodeType)("Expression")
  1322. },
  1323. quasi: {
  1324. validate: (0, _utils.assertNodeType)("TemplateLiteral")
  1325. },
  1326. ["typeParameters"]: {
  1327. validate: (0, _utils.assertNodeType)("TypeParameterInstantiation", "TSTypeParameterInstantiation"),
  1328. optional: true
  1329. }
  1330. }
  1331. });
  1332. defineType("TemplateElement", {
  1333. builder: ["value", "tail"],
  1334. fields: {
  1335. value: {
  1336. validate: (0, _utils.chain)((0, _utils.assertShape)({
  1337. raw: {
  1338. validate: (0, _utils.assertValueType)("string")
  1339. },
  1340. cooked: {
  1341. validate: (0, _utils.assertValueType)("string"),
  1342. optional: true
  1343. }
  1344. }), function templateElementCookedValidator(node) {
  1345. const raw = node.value.raw;
  1346. let unterminatedCalled = false;
  1347. const error = () => {
  1348. throw new Error("Internal @babel/types error.");
  1349. };
  1350. const {
  1351. str,
  1352. firstInvalidLoc
  1353. } = (0, _helperStringParser.readStringContents)("template", raw, 0, 0, 0, {
  1354. unterminated() {
  1355. unterminatedCalled = true;
  1356. },
  1357. strictNumericEscape: error,
  1358. invalidEscapeSequence: error,
  1359. numericSeparatorInEscapeSequence: error,
  1360. unexpectedNumericSeparator: error,
  1361. invalidDigit: error,
  1362. invalidCodePoint: error
  1363. });
  1364. if (!unterminatedCalled) throw new Error("Invalid raw");
  1365. node.value.cooked = firstInvalidLoc ? null : str;
  1366. })
  1367. },
  1368. tail: {
  1369. default: false
  1370. }
  1371. }
  1372. });
  1373. defineType("TemplateLiteral", {
  1374. visitor: ["quasis", "expressions"],
  1375. aliases: ["Expression", "Literal"],
  1376. fields: {
  1377. quasis: (0, _utils.validateArrayOfType)("TemplateElement"),
  1378. expressions: {
  1379. validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Expression", "TSType")), function (node, key, val) {
  1380. if (node.quasis.length !== val.length + 1) {
  1381. 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}`);
  1382. }
  1383. })
  1384. }
  1385. }
  1386. });
  1387. defineType("YieldExpression", {
  1388. builder: ["argument", "delegate"],
  1389. visitor: ["argument"],
  1390. aliases: ["Expression", "Terminatorless"],
  1391. fields: {
  1392. delegate: {
  1393. validate: process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.chain)((0, _utils.assertValueType)("boolean"), Object.assign(function (node, key, val) {
  1394. if (val && !node.argument) {
  1395. throw new TypeError("Property delegate of YieldExpression cannot be true if there is no argument");
  1396. }
  1397. }, {
  1398. type: "boolean"
  1399. })) : (0, _utils.assertValueType)("boolean"),
  1400. default: false
  1401. },
  1402. argument: {
  1403. optional: true,
  1404. validate: (0, _utils.assertNodeType)("Expression")
  1405. }
  1406. }
  1407. });
  1408. defineType("AwaitExpression", {
  1409. builder: ["argument"],
  1410. visitor: ["argument"],
  1411. aliases: ["Expression", "Terminatorless"],
  1412. fields: {
  1413. argument: {
  1414. validate: (0, _utils.assertNodeType)("Expression")
  1415. }
  1416. }
  1417. });
  1418. defineType("Import", {
  1419. aliases: ["Expression"]
  1420. });
  1421. defineType("BigIntLiteral", {
  1422. builder: ["value"],
  1423. fields: {
  1424. value: {
  1425. validate: (0, _utils.assertValueType)("string")
  1426. }
  1427. },
  1428. aliases: ["Expression", "Pureish", "Literal", "Immutable"]
  1429. });
  1430. defineType("ExportNamespaceSpecifier", {
  1431. visitor: ["exported"],
  1432. aliases: ["ModuleSpecifier"],
  1433. fields: {
  1434. exported: {
  1435. validate: (0, _utils.assertNodeType)("Identifier")
  1436. }
  1437. }
  1438. });
  1439. defineType("OptionalMemberExpression", {
  1440. builder: ["object", "property", "computed", "optional"],
  1441. visitor: ["object", "property"],
  1442. aliases: ["Expression"],
  1443. fields: {
  1444. object: {
  1445. validate: (0, _utils.assertNodeType)("Expression")
  1446. },
  1447. property: {
  1448. validate: function () {
  1449. const normal = (0, _utils.assertNodeType)("Identifier");
  1450. const computed = (0, _utils.assertNodeType)("Expression");
  1451. const validator = Object.assign(function (node, key, val) {
  1452. const validator = node.computed ? computed : normal;
  1453. validator(node, key, val);
  1454. }, {
  1455. oneOfNodeTypes: ["Expression", "Identifier"]
  1456. });
  1457. return validator;
  1458. }()
  1459. },
  1460. computed: {
  1461. default: false
  1462. },
  1463. optional: {
  1464. validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertValueType)("boolean") : (0, _utils.chain)((0, _utils.assertValueType)("boolean"), (0, _utils.assertOptionalChainStart)())
  1465. }
  1466. }
  1467. });
  1468. defineType("OptionalCallExpression", {
  1469. visitor: ["callee", "typeParameters", "typeArguments", "arguments"],
  1470. builder: ["callee", "arguments", "optional"],
  1471. aliases: ["Expression"],
  1472. fields: Object.assign({
  1473. callee: {
  1474. validate: (0, _utils.assertNodeType)("Expression")
  1475. },
  1476. arguments: (0, _utils.validateArrayOfType)("Expression", "SpreadElement", "ArgumentPlaceholder"),
  1477. optional: {
  1478. validate: !process.env.BABEL_TYPES_8_BREAKING ? (0, _utils.assertValueType)("boolean") : (0, _utils.chain)((0, _utils.assertValueType)("boolean"), (0, _utils.assertOptionalChainStart)())
  1479. },
  1480. typeArguments: {
  1481. validate: (0, _utils.assertNodeType)("TypeParameterInstantiation"),
  1482. optional: true
  1483. }
  1484. }, {
  1485. typeParameters: {
  1486. validate: (0, _utils.assertNodeType)("TSTypeParameterInstantiation"),
  1487. optional: true
  1488. }
  1489. })
  1490. });
  1491. defineType("ClassProperty", {
  1492. visitor: ["decorators", "variance", "key", "typeAnnotation", "value"],
  1493. builder: ["key", "value", "typeAnnotation", "decorators", "computed", "static"],
  1494. aliases: ["Property"],
  1495. fields: Object.assign({}, classMethodOrPropertyCommon(), {
  1496. value: {
  1497. validate: (0, _utils.assertNodeType)("Expression"),
  1498. optional: true
  1499. },
  1500. definite: {
  1501. validate: (0, _utils.assertValueType)("boolean"),
  1502. optional: true
  1503. },
  1504. typeAnnotation: {
  1505. validate: (0, _utils.assertNodeType)("TypeAnnotation", "TSTypeAnnotation", "Noop"),
  1506. optional: true
  1507. },
  1508. decorators: {
  1509. validate: (0, _utils.arrayOfType)("Decorator"),
  1510. optional: true
  1511. },
  1512. readonly: {
  1513. validate: (0, _utils.assertValueType)("boolean"),
  1514. optional: true
  1515. },
  1516. declare: {
  1517. validate: (0, _utils.assertValueType)("boolean"),
  1518. optional: true
  1519. },
  1520. variance: {
  1521. validate: (0, _utils.assertNodeType)("Variance"),
  1522. optional: true
  1523. }
  1524. })
  1525. });
  1526. defineType("ClassAccessorProperty", {
  1527. visitor: ["decorators", "key", "typeAnnotation", "value"],
  1528. builder: ["key", "value", "typeAnnotation", "decorators", "computed", "static"],
  1529. aliases: ["Property", "Accessor"],
  1530. fields: Object.assign({}, classMethodOrPropertyCommon(), {
  1531. key: {
  1532. validate: (0, _utils.chain)(function () {
  1533. const normal = (0, _utils.assertNodeType)("Identifier", "StringLiteral", "NumericLiteral", "BigIntLiteral", "PrivateName");
  1534. const computed = (0, _utils.assertNodeType)("Expression");
  1535. return function (node, key, val) {
  1536. const validator = node.computed ? computed : normal;
  1537. validator(node, key, val);
  1538. };
  1539. }(), (0, _utils.assertNodeType)("Identifier", "StringLiteral", "NumericLiteral", "BigIntLiteral", "Expression", "PrivateName"))
  1540. },
  1541. value: {
  1542. validate: (0, _utils.assertNodeType)("Expression"),
  1543. optional: true
  1544. },
  1545. definite: {
  1546. validate: (0, _utils.assertValueType)("boolean"),
  1547. optional: true
  1548. },
  1549. typeAnnotation: {
  1550. validate: (0, _utils.assertNodeType)("TypeAnnotation", "TSTypeAnnotation", "Noop"),
  1551. optional: true
  1552. },
  1553. decorators: {
  1554. validate: (0, _utils.arrayOfType)("Decorator"),
  1555. optional: true
  1556. },
  1557. readonly: {
  1558. validate: (0, _utils.assertValueType)("boolean"),
  1559. optional: true
  1560. },
  1561. declare: {
  1562. validate: (0, _utils.assertValueType)("boolean"),
  1563. optional: true
  1564. },
  1565. variance: {
  1566. validate: (0, _utils.assertNodeType)("Variance"),
  1567. optional: true
  1568. }
  1569. })
  1570. });
  1571. defineType("ClassPrivateProperty", {
  1572. visitor: ["decorators", "variance", "key", "typeAnnotation", "value"],
  1573. builder: ["key", "value", "decorators", "static"],
  1574. aliases: ["Property", "Private"],
  1575. fields: {
  1576. key: {
  1577. validate: (0, _utils.assertNodeType)("PrivateName")
  1578. },
  1579. value: {
  1580. validate: (0, _utils.assertNodeType)("Expression"),
  1581. optional: true
  1582. },
  1583. typeAnnotation: {
  1584. validate: (0, _utils.assertNodeType)("TypeAnnotation", "TSTypeAnnotation", "Noop"),
  1585. optional: true
  1586. },
  1587. decorators: {
  1588. validate: (0, _utils.arrayOfType)("Decorator"),
  1589. optional: true
  1590. },
  1591. static: {
  1592. validate: (0, _utils.assertValueType)("boolean"),
  1593. default: false
  1594. },
  1595. readonly: {
  1596. validate: (0, _utils.assertValueType)("boolean"),
  1597. optional: true
  1598. },
  1599. optional: {
  1600. validate: (0, _utils.assertValueType)("boolean"),
  1601. optional: true
  1602. },
  1603. definite: {
  1604. validate: (0, _utils.assertValueType)("boolean"),
  1605. optional: true
  1606. },
  1607. variance: {
  1608. validate: (0, _utils.assertNodeType)("Variance"),
  1609. optional: true
  1610. }
  1611. }
  1612. });
  1613. defineType("ClassPrivateMethod", {
  1614. builder: ["kind", "key", "params", "body", "static"],
  1615. visitor: ["decorators", "key", "typeParameters", "params", "returnType", "body"],
  1616. aliases: ["Function", "Scopable", "BlockParent", "FunctionParent", "Method", "Private"],
  1617. fields: Object.assign({}, classMethodOrDeclareMethodCommon(), functionTypeAnnotationCommon(), {
  1618. kind: {
  1619. validate: (0, _utils.assertOneOf)("get", "set", "method"),
  1620. default: "method"
  1621. },
  1622. key: {
  1623. validate: (0, _utils.assertNodeType)("PrivateName")
  1624. },
  1625. body: {
  1626. validate: (0, _utils.assertNodeType)("BlockStatement")
  1627. }
  1628. })
  1629. });
  1630. defineType("PrivateName", {
  1631. visitor: ["id"],
  1632. aliases: ["Private"],
  1633. fields: {
  1634. id: {
  1635. validate: (0, _utils.assertNodeType)("Identifier")
  1636. }
  1637. }
  1638. });
  1639. defineType("StaticBlock", {
  1640. visitor: ["body"],
  1641. fields: {
  1642. body: (0, _utils.validateArrayOfType)("Statement")
  1643. },
  1644. aliases: ["Scopable", "BlockParent", "FunctionParent"]
  1645. });
  1646. defineType("ImportAttribute", {
  1647. visitor: ["key", "value"],
  1648. fields: {
  1649. key: {
  1650. validate: (0, _utils.assertNodeType)("Identifier", "StringLiteral")
  1651. },
  1652. value: {
  1653. validate: (0, _utils.assertNodeType)("StringLiteral")
  1654. }
  1655. }
  1656. });
  1657. //# sourceMappingURL=core.js.map