Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

core.js 46KB

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