f105a4c7528de8856c647e9cfc315fb32c4795272fdf7a5653a5b734f1080fa77acdef6b82ac8ebac32842b707b0c53440b24ddc285ff49adb1bc2a4dd6e66 52 KB

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