node.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. /*
  2. Package ast declares types representing a JavaScript AST.
  3. # Warning
  4. The parser and AST interfaces are still works-in-progress (particularly where
  5. node types are concerned) and may change in the future.
  6. */
  7. package ast
  8. import (
  9. "github.com/dop251/goja/file"
  10. "github.com/dop251/goja/token"
  11. "github.com/dop251/goja/unistring"
  12. )
  13. type PropertyKind string
  14. const (
  15. PropertyKindValue PropertyKind = "value"
  16. PropertyKindGet PropertyKind = "get"
  17. PropertyKindSet PropertyKind = "set"
  18. PropertyKindMethod PropertyKind = "method"
  19. )
  20. // All nodes implement the Node interface.
  21. type Node interface {
  22. Idx0() file.Idx // The index of the first character belonging to the node
  23. Idx1() file.Idx // The index of the first character immediately after the node
  24. }
  25. // ========== //
  26. // Expression //
  27. // ========== //
  28. type (
  29. // All expression nodes implement the Expression interface.
  30. Expression interface {
  31. Node
  32. _expressionNode()
  33. }
  34. BindingTarget interface {
  35. Expression
  36. _bindingTarget()
  37. }
  38. Binding struct {
  39. Target BindingTarget
  40. Initializer Expression
  41. }
  42. Pattern interface {
  43. BindingTarget
  44. _pattern()
  45. }
  46. YieldExpression struct {
  47. Yield file.Idx
  48. Argument Expression
  49. Delegate bool
  50. }
  51. AwaitExpression struct {
  52. Await file.Idx
  53. Argument Expression
  54. }
  55. ArrayLiteral struct {
  56. LeftBracket file.Idx
  57. RightBracket file.Idx
  58. Value []Expression
  59. }
  60. ArrayPattern struct {
  61. LeftBracket file.Idx
  62. RightBracket file.Idx
  63. Elements []Expression
  64. Rest Expression
  65. }
  66. AssignExpression struct {
  67. Operator token.Token
  68. Left Expression
  69. Right Expression
  70. }
  71. BadExpression struct {
  72. From file.Idx
  73. To file.Idx
  74. }
  75. BinaryExpression struct {
  76. Operator token.Token
  77. Left Expression
  78. Right Expression
  79. Comparison bool
  80. }
  81. BooleanLiteral struct {
  82. Idx file.Idx
  83. Literal string
  84. Value bool
  85. }
  86. BracketExpression struct {
  87. Left Expression
  88. Member Expression
  89. LeftBracket file.Idx
  90. RightBracket file.Idx
  91. }
  92. CallExpression struct {
  93. Callee Expression
  94. LeftParenthesis file.Idx
  95. ArgumentList []Expression
  96. RightParenthesis file.Idx
  97. }
  98. ConditionalExpression struct {
  99. Test Expression
  100. Consequent Expression
  101. Alternate Expression
  102. }
  103. DotExpression struct {
  104. Left Expression
  105. Identifier Identifier
  106. }
  107. PrivateDotExpression struct {
  108. Left Expression
  109. Identifier PrivateIdentifier
  110. }
  111. OptionalChain struct {
  112. Expression
  113. }
  114. Optional struct {
  115. Expression
  116. }
  117. FunctionLiteral struct {
  118. Function file.Idx
  119. Name *Identifier
  120. ParameterList *ParameterList
  121. Body *BlockStatement
  122. Source string
  123. DeclarationList []*VariableDeclaration
  124. Async, Generator bool
  125. }
  126. ClassLiteral struct {
  127. Class file.Idx
  128. RightBrace file.Idx
  129. Name *Identifier
  130. SuperClass Expression
  131. Body []ClassElement
  132. Source string
  133. }
  134. ConciseBody interface {
  135. Node
  136. _conciseBody()
  137. }
  138. ExpressionBody struct {
  139. Expression Expression
  140. }
  141. ArrowFunctionLiteral struct {
  142. Start file.Idx
  143. ParameterList *ParameterList
  144. Body ConciseBody
  145. Source string
  146. DeclarationList []*VariableDeclaration
  147. Async bool
  148. }
  149. Identifier struct {
  150. Name unistring.String
  151. Idx file.Idx
  152. }
  153. PrivateIdentifier struct {
  154. Identifier
  155. }
  156. NewExpression struct {
  157. New file.Idx
  158. Callee Expression
  159. LeftParenthesis file.Idx
  160. ArgumentList []Expression
  161. RightParenthesis file.Idx
  162. }
  163. NullLiteral struct {
  164. Idx file.Idx
  165. Literal string
  166. }
  167. NumberLiteral struct {
  168. Idx file.Idx
  169. Literal string
  170. Value interface{}
  171. }
  172. ObjectLiteral struct {
  173. LeftBrace file.Idx
  174. RightBrace file.Idx
  175. Value []Property
  176. }
  177. ObjectPattern struct {
  178. LeftBrace file.Idx
  179. RightBrace file.Idx
  180. Properties []Property
  181. Rest Expression
  182. }
  183. ParameterList struct {
  184. Opening file.Idx
  185. List []*Binding
  186. Rest Expression
  187. Closing file.Idx
  188. }
  189. Property interface {
  190. Expression
  191. _property()
  192. }
  193. PropertyShort struct {
  194. Name Identifier
  195. Initializer Expression
  196. }
  197. PropertyKeyed struct {
  198. Key Expression
  199. Kind PropertyKind
  200. Value Expression
  201. Computed bool
  202. }
  203. SpreadElement struct {
  204. Expression
  205. }
  206. RegExpLiteral struct {
  207. Idx file.Idx
  208. Literal string
  209. Pattern string
  210. Flags string
  211. }
  212. SequenceExpression struct {
  213. Sequence []Expression
  214. }
  215. StringLiteral struct {
  216. Idx file.Idx
  217. Literal string
  218. Value unistring.String
  219. }
  220. TemplateElement struct {
  221. Idx file.Idx
  222. Literal string
  223. Parsed unistring.String
  224. Valid bool
  225. }
  226. TemplateLiteral struct {
  227. OpenQuote file.Idx
  228. CloseQuote file.Idx
  229. Tag Expression
  230. Elements []*TemplateElement
  231. Expressions []Expression
  232. }
  233. ThisExpression struct {
  234. Idx file.Idx
  235. }
  236. SuperExpression struct {
  237. Idx file.Idx
  238. }
  239. UnaryExpression struct {
  240. Operator token.Token
  241. Idx file.Idx // If a prefix operation
  242. Operand Expression
  243. Postfix bool
  244. }
  245. MetaProperty struct {
  246. Meta, Property *Identifier
  247. Idx file.Idx
  248. }
  249. )
  250. // _expressionNode
  251. func (*ArrayLiteral) _expressionNode() {}
  252. func (*AssignExpression) _expressionNode() {}
  253. func (*YieldExpression) _expressionNode() {}
  254. func (*AwaitExpression) _expressionNode() {}
  255. func (*BadExpression) _expressionNode() {}
  256. func (*BinaryExpression) _expressionNode() {}
  257. func (*BooleanLiteral) _expressionNode() {}
  258. func (*BracketExpression) _expressionNode() {}
  259. func (*CallExpression) _expressionNode() {}
  260. func (*ConditionalExpression) _expressionNode() {}
  261. func (*DotExpression) _expressionNode() {}
  262. func (*PrivateDotExpression) _expressionNode() {}
  263. func (*FunctionLiteral) _expressionNode() {}
  264. func (*ClassLiteral) _expressionNode() {}
  265. func (*ArrowFunctionLiteral) _expressionNode() {}
  266. func (*Identifier) _expressionNode() {}
  267. func (*NewExpression) _expressionNode() {}
  268. func (*NullLiteral) _expressionNode() {}
  269. func (*NumberLiteral) _expressionNode() {}
  270. func (*ObjectLiteral) _expressionNode() {}
  271. func (*RegExpLiteral) _expressionNode() {}
  272. func (*SequenceExpression) _expressionNode() {}
  273. func (*StringLiteral) _expressionNode() {}
  274. func (*TemplateLiteral) _expressionNode() {}
  275. func (*ThisExpression) _expressionNode() {}
  276. func (*SuperExpression) _expressionNode() {}
  277. func (*UnaryExpression) _expressionNode() {}
  278. func (*MetaProperty) _expressionNode() {}
  279. func (*ObjectPattern) _expressionNode() {}
  280. func (*ArrayPattern) _expressionNode() {}
  281. func (*Binding) _expressionNode() {}
  282. func (*PropertyShort) _expressionNode() {}
  283. func (*PropertyKeyed) _expressionNode() {}
  284. // ========= //
  285. // Statement //
  286. // ========= //
  287. type (
  288. // All statement nodes implement the Statement interface.
  289. Statement interface {
  290. Node
  291. _statementNode()
  292. }
  293. BadStatement struct {
  294. From file.Idx
  295. To file.Idx
  296. }
  297. BlockStatement struct {
  298. LeftBrace file.Idx
  299. List []Statement
  300. RightBrace file.Idx
  301. }
  302. BranchStatement struct {
  303. Idx file.Idx
  304. Token token.Token
  305. Label *Identifier
  306. }
  307. CaseStatement struct {
  308. Case file.Idx
  309. Test Expression
  310. Consequent []Statement
  311. }
  312. CatchStatement struct {
  313. Catch file.Idx
  314. Parameter BindingTarget
  315. Body *BlockStatement
  316. }
  317. DebuggerStatement struct {
  318. Debugger file.Idx
  319. }
  320. DoWhileStatement struct {
  321. Do file.Idx
  322. Test Expression
  323. Body Statement
  324. RightParenthesis file.Idx
  325. }
  326. EmptyStatement struct {
  327. Semicolon file.Idx
  328. }
  329. ExpressionStatement struct {
  330. Expression Expression
  331. }
  332. ForInStatement struct {
  333. For file.Idx
  334. Into ForInto
  335. Source Expression
  336. Body Statement
  337. }
  338. ForOfStatement struct {
  339. For file.Idx
  340. Into ForInto
  341. Source Expression
  342. Body Statement
  343. }
  344. ForStatement struct {
  345. For file.Idx
  346. Initializer ForLoopInitializer
  347. Update Expression
  348. Test Expression
  349. Body Statement
  350. }
  351. IfStatement struct {
  352. If file.Idx
  353. Test Expression
  354. Consequent Statement
  355. Alternate Statement
  356. }
  357. LabelledStatement struct {
  358. Label *Identifier
  359. Colon file.Idx
  360. Statement Statement
  361. }
  362. ReturnStatement struct {
  363. Return file.Idx
  364. Argument Expression
  365. }
  366. SwitchStatement struct {
  367. Switch file.Idx
  368. Discriminant Expression
  369. Default int
  370. Body []*CaseStatement
  371. RightBrace file.Idx
  372. }
  373. ThrowStatement struct {
  374. Throw file.Idx
  375. Argument Expression
  376. }
  377. TryStatement struct {
  378. Try file.Idx
  379. Body *BlockStatement
  380. Catch *CatchStatement
  381. Finally *BlockStatement
  382. }
  383. VariableStatement struct {
  384. Var file.Idx
  385. List []*Binding
  386. }
  387. LexicalDeclaration struct {
  388. Idx file.Idx
  389. Token token.Token
  390. List []*Binding
  391. }
  392. WhileStatement struct {
  393. While file.Idx
  394. Test Expression
  395. Body Statement
  396. }
  397. WithStatement struct {
  398. With file.Idx
  399. Object Expression
  400. Body Statement
  401. }
  402. FunctionDeclaration struct {
  403. Function *FunctionLiteral
  404. }
  405. ClassDeclaration struct {
  406. Class *ClassLiteral
  407. }
  408. )
  409. // _statementNode
  410. func (*BadStatement) _statementNode() {}
  411. func (*BlockStatement) _statementNode() {}
  412. func (*BranchStatement) _statementNode() {}
  413. func (*CaseStatement) _statementNode() {}
  414. func (*CatchStatement) _statementNode() {}
  415. func (*DebuggerStatement) _statementNode() {}
  416. func (*DoWhileStatement) _statementNode() {}
  417. func (*EmptyStatement) _statementNode() {}
  418. func (*ExpressionStatement) _statementNode() {}
  419. func (*ForInStatement) _statementNode() {}
  420. func (*ForOfStatement) _statementNode() {}
  421. func (*ForStatement) _statementNode() {}
  422. func (*IfStatement) _statementNode() {}
  423. func (*LabelledStatement) _statementNode() {}
  424. func (*ReturnStatement) _statementNode() {}
  425. func (*SwitchStatement) _statementNode() {}
  426. func (*ThrowStatement) _statementNode() {}
  427. func (*TryStatement) _statementNode() {}
  428. func (*VariableStatement) _statementNode() {}
  429. func (*WhileStatement) _statementNode() {}
  430. func (*WithStatement) _statementNode() {}
  431. func (*LexicalDeclaration) _statementNode() {}
  432. func (*FunctionDeclaration) _statementNode() {}
  433. func (*ClassDeclaration) _statementNode() {}
  434. // =========== //
  435. // Declaration //
  436. // =========== //
  437. type (
  438. VariableDeclaration struct {
  439. Var file.Idx
  440. List []*Binding
  441. }
  442. ClassElement interface {
  443. Node
  444. _classElement()
  445. }
  446. FieldDefinition struct {
  447. Idx file.Idx
  448. Key Expression
  449. Initializer Expression
  450. Computed bool
  451. Static bool
  452. }
  453. MethodDefinition struct {
  454. Idx file.Idx
  455. Key Expression
  456. Kind PropertyKind // "method", "get" or "set"
  457. Body *FunctionLiteral
  458. Computed bool
  459. Static bool
  460. }
  461. ClassStaticBlock struct {
  462. Static file.Idx
  463. Block *BlockStatement
  464. Source string
  465. DeclarationList []*VariableDeclaration
  466. }
  467. )
  468. type (
  469. ForLoopInitializer interface {
  470. Node
  471. _forLoopInitializer()
  472. }
  473. ForLoopInitializerExpression struct {
  474. Expression Expression
  475. }
  476. ForLoopInitializerVarDeclList struct {
  477. Var file.Idx
  478. List []*Binding
  479. }
  480. ForLoopInitializerLexicalDecl struct {
  481. LexicalDeclaration LexicalDeclaration
  482. }
  483. ForInto interface {
  484. Node
  485. _forInto()
  486. }
  487. ForIntoVar struct {
  488. Binding *Binding
  489. }
  490. ForDeclaration struct {
  491. Idx file.Idx
  492. IsConst bool
  493. Target BindingTarget
  494. }
  495. ForIntoExpression struct {
  496. Expression Expression
  497. }
  498. )
  499. func (*ForLoopInitializerExpression) _forLoopInitializer() {}
  500. func (*ForLoopInitializerVarDeclList) _forLoopInitializer() {}
  501. func (*ForLoopInitializerLexicalDecl) _forLoopInitializer() {}
  502. func (*ForIntoVar) _forInto() {}
  503. func (*ForDeclaration) _forInto() {}
  504. func (*ForIntoExpression) _forInto() {}
  505. func (*ArrayPattern) _pattern() {}
  506. func (*ArrayPattern) _bindingTarget() {}
  507. func (*ObjectPattern) _pattern() {}
  508. func (*ObjectPattern) _bindingTarget() {}
  509. func (*BadExpression) _bindingTarget() {}
  510. func (*PropertyShort) _property() {}
  511. func (*PropertyKeyed) _property() {}
  512. func (*SpreadElement) _property() {}
  513. func (*Identifier) _bindingTarget() {}
  514. func (*BlockStatement) _conciseBody() {}
  515. func (*ExpressionBody) _conciseBody() {}
  516. func (*FieldDefinition) _classElement() {}
  517. func (*MethodDefinition) _classElement() {}
  518. func (*ClassStaticBlock) _classElement() {}
  519. // ==== //
  520. // Node //
  521. // ==== //
  522. type Program struct {
  523. Body []Statement
  524. DeclarationList []*VariableDeclaration
  525. File *file.File
  526. }
  527. // ==== //
  528. // Idx0 //
  529. // ==== //
  530. func (self *ArrayLiteral) Idx0() file.Idx { return self.LeftBracket }
  531. func (self *ArrayPattern) Idx0() file.Idx { return self.LeftBracket }
  532. func (self *YieldExpression) Idx0() file.Idx { return self.Yield }
  533. func (self *AwaitExpression) Idx0() file.Idx { return self.Await }
  534. func (self *ObjectPattern) Idx0() file.Idx { return self.LeftBrace }
  535. func (self *ParameterList) Idx0() file.Idx { return self.Opening }
  536. func (self *AssignExpression) Idx0() file.Idx { return self.Left.Idx0() }
  537. func (self *BadExpression) Idx0() file.Idx { return self.From }
  538. func (self *BinaryExpression) Idx0() file.Idx { return self.Left.Idx0() }
  539. func (self *BooleanLiteral) Idx0() file.Idx { return self.Idx }
  540. func (self *BracketExpression) Idx0() file.Idx { return self.Left.Idx0() }
  541. func (self *CallExpression) Idx0() file.Idx { return self.Callee.Idx0() }
  542. func (self *ConditionalExpression) Idx0() file.Idx { return self.Test.Idx0() }
  543. func (self *DotExpression) Idx0() file.Idx { return self.Left.Idx0() }
  544. func (self *PrivateDotExpression) Idx0() file.Idx { return self.Left.Idx0() }
  545. func (self *FunctionLiteral) Idx0() file.Idx { return self.Function }
  546. func (self *ClassLiteral) Idx0() file.Idx { return self.Class }
  547. func (self *ArrowFunctionLiteral) Idx0() file.Idx { return self.Start }
  548. func (self *Identifier) Idx0() file.Idx { return self.Idx }
  549. func (self *NewExpression) Idx0() file.Idx { return self.New }
  550. func (self *NullLiteral) Idx0() file.Idx { return self.Idx }
  551. func (self *NumberLiteral) Idx0() file.Idx { return self.Idx }
  552. func (self *ObjectLiteral) Idx0() file.Idx { return self.LeftBrace }
  553. func (self *RegExpLiteral) Idx0() file.Idx { return self.Idx }
  554. func (self *SequenceExpression) Idx0() file.Idx { return self.Sequence[0].Idx0() }
  555. func (self *StringLiteral) Idx0() file.Idx { return self.Idx }
  556. func (self *TemplateElement) Idx0() file.Idx { return self.Idx }
  557. func (self *TemplateLiteral) Idx0() file.Idx { return self.OpenQuote }
  558. func (self *ThisExpression) Idx0() file.Idx { return self.Idx }
  559. func (self *SuperExpression) Idx0() file.Idx { return self.Idx }
  560. func (self *UnaryExpression) Idx0() file.Idx {
  561. if self.Postfix {
  562. return self.Operand.Idx0()
  563. }
  564. return self.Idx
  565. }
  566. func (self *MetaProperty) Idx0() file.Idx { return self.Idx }
  567. func (self *BadStatement) Idx0() file.Idx { return self.From }
  568. func (self *BlockStatement) Idx0() file.Idx { return self.LeftBrace }
  569. func (self *BranchStatement) Idx0() file.Idx { return self.Idx }
  570. func (self *CaseStatement) Idx0() file.Idx { return self.Case }
  571. func (self *CatchStatement) Idx0() file.Idx { return self.Catch }
  572. func (self *DebuggerStatement) Idx0() file.Idx { return self.Debugger }
  573. func (self *DoWhileStatement) Idx0() file.Idx { return self.Do }
  574. func (self *EmptyStatement) Idx0() file.Idx { return self.Semicolon }
  575. func (self *ExpressionStatement) Idx0() file.Idx { return self.Expression.Idx0() }
  576. func (self *ForInStatement) Idx0() file.Idx { return self.For }
  577. func (self *ForOfStatement) Idx0() file.Idx { return self.For }
  578. func (self *ForStatement) Idx0() file.Idx { return self.For }
  579. func (self *IfStatement) Idx0() file.Idx { return self.If }
  580. func (self *LabelledStatement) Idx0() file.Idx { return self.Label.Idx0() }
  581. func (self *Program) Idx0() file.Idx { return self.Body[0].Idx0() }
  582. func (self *ReturnStatement) Idx0() file.Idx { return self.Return }
  583. func (self *SwitchStatement) Idx0() file.Idx { return self.Switch }
  584. func (self *ThrowStatement) Idx0() file.Idx { return self.Throw }
  585. func (self *TryStatement) Idx0() file.Idx { return self.Try }
  586. func (self *VariableStatement) Idx0() file.Idx { return self.Var }
  587. func (self *WhileStatement) Idx0() file.Idx { return self.While }
  588. func (self *WithStatement) Idx0() file.Idx { return self.With }
  589. func (self *LexicalDeclaration) Idx0() file.Idx { return self.Idx }
  590. func (self *FunctionDeclaration) Idx0() file.Idx { return self.Function.Idx0() }
  591. func (self *ClassDeclaration) Idx0() file.Idx { return self.Class.Idx0() }
  592. func (self *Binding) Idx0() file.Idx { return self.Target.Idx0() }
  593. func (self *ForLoopInitializerExpression) Idx0() file.Idx { return self.Expression.Idx0() }
  594. func (self *ForLoopInitializerVarDeclList) Idx0() file.Idx { return self.List[0].Idx0() }
  595. func (self *ForLoopInitializerLexicalDecl) Idx0() file.Idx { return self.LexicalDeclaration.Idx0() }
  596. func (self *PropertyShort) Idx0() file.Idx { return self.Name.Idx }
  597. func (self *PropertyKeyed) Idx0() file.Idx { return self.Key.Idx0() }
  598. func (self *ExpressionBody) Idx0() file.Idx { return self.Expression.Idx0() }
  599. func (self *VariableDeclaration) Idx0() file.Idx { return self.Var }
  600. func (self *FieldDefinition) Idx0() file.Idx { return self.Idx }
  601. func (self *MethodDefinition) Idx0() file.Idx { return self.Idx }
  602. func (self *ClassStaticBlock) Idx0() file.Idx { return self.Static }
  603. func (self *ForDeclaration) Idx0() file.Idx { return self.Idx }
  604. func (self *ForIntoVar) Idx0() file.Idx { return self.Binding.Idx0() }
  605. func (self *ForIntoExpression) Idx0() file.Idx { return self.Expression.Idx0() }
  606. // ==== //
  607. // Idx1 //
  608. // ==== //
  609. func (self *ArrayLiteral) Idx1() file.Idx { return self.RightBracket + 1 }
  610. func (self *ArrayPattern) Idx1() file.Idx { return self.RightBracket + 1 }
  611. func (self *AssignExpression) Idx1() file.Idx { return self.Right.Idx1() }
  612. func (self *AwaitExpression) Idx1() file.Idx { return self.Argument.Idx1() }
  613. func (self *BadExpression) Idx1() file.Idx { return self.To }
  614. func (self *BinaryExpression) Idx1() file.Idx { return self.Right.Idx1() }
  615. func (self *BooleanLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
  616. func (self *BracketExpression) Idx1() file.Idx { return self.RightBracket + 1 }
  617. func (self *CallExpression) Idx1() file.Idx { return self.RightParenthesis + 1 }
  618. func (self *ConditionalExpression) Idx1() file.Idx { return self.Alternate.Idx1() }
  619. func (self *DotExpression) Idx1() file.Idx { return self.Identifier.Idx1() }
  620. func (self *PrivateDotExpression) Idx1() file.Idx { return self.Identifier.Idx1() }
  621. func (self *FunctionLiteral) Idx1() file.Idx { return self.Body.Idx1() }
  622. func (self *ClassLiteral) Idx1() file.Idx { return self.RightBrace + 1 }
  623. func (self *ArrowFunctionLiteral) Idx1() file.Idx { return self.Body.Idx1() }
  624. func (self *Identifier) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Name)) }
  625. func (self *NewExpression) Idx1() file.Idx {
  626. if self.ArgumentList != nil {
  627. return self.RightParenthesis + 1
  628. } else {
  629. return self.Callee.Idx1()
  630. }
  631. }
  632. func (self *NullLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + 4) } // "null"
  633. func (self *NumberLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
  634. func (self *ObjectLiteral) Idx1() file.Idx { return self.RightBrace + 1 }
  635. func (self *ObjectPattern) Idx1() file.Idx { return self.RightBrace + 1 }
  636. func (self *ParameterList) Idx1() file.Idx { return self.Closing + 1 }
  637. func (self *RegExpLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
  638. func (self *SequenceExpression) Idx1() file.Idx { return self.Sequence[len(self.Sequence)-1].Idx1() }
  639. func (self *StringLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
  640. func (self *TemplateElement) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
  641. func (self *TemplateLiteral) Idx1() file.Idx { return self.CloseQuote + 1 }
  642. func (self *ThisExpression) Idx1() file.Idx { return self.Idx + 4 }
  643. func (self *SuperExpression) Idx1() file.Idx { return self.Idx + 5 }
  644. func (self *UnaryExpression) Idx1() file.Idx {
  645. if self.Postfix {
  646. return self.Operand.Idx1() + 2 // ++ --
  647. }
  648. return self.Operand.Idx1()
  649. }
  650. func (self *MetaProperty) Idx1() file.Idx {
  651. return self.Property.Idx1()
  652. }
  653. func (self *BadStatement) Idx1() file.Idx { return self.To }
  654. func (self *BlockStatement) Idx1() file.Idx { return self.RightBrace + 1 }
  655. func (self *BranchStatement) Idx1() file.Idx {
  656. if self.Label == nil {
  657. return file.Idx(int(self.Idx) + len(self.Token.String()))
  658. }
  659. return self.Label.Idx1()
  660. }
  661. func (self *CaseStatement) Idx1() file.Idx { return self.Consequent[len(self.Consequent)-1].Idx1() }
  662. func (self *CatchStatement) Idx1() file.Idx { return self.Body.Idx1() }
  663. func (self *DebuggerStatement) Idx1() file.Idx { return self.Debugger + 8 }
  664. func (self *DoWhileStatement) Idx1() file.Idx { return self.RightParenthesis + 1 }
  665. func (self *EmptyStatement) Idx1() file.Idx { return self.Semicolon + 1 }
  666. func (self *ExpressionStatement) Idx1() file.Idx { return self.Expression.Idx1() }
  667. func (self *ForInStatement) Idx1() file.Idx { return self.Body.Idx1() }
  668. func (self *ForOfStatement) Idx1() file.Idx { return self.Body.Idx1() }
  669. func (self *ForStatement) Idx1() file.Idx { return self.Body.Idx1() }
  670. func (self *IfStatement) Idx1() file.Idx {
  671. if self.Alternate != nil {
  672. return self.Alternate.Idx1()
  673. }
  674. return self.Consequent.Idx1()
  675. }
  676. func (self *LabelledStatement) Idx1() file.Idx { return self.Statement.Idx1() }
  677. func (self *Program) Idx1() file.Idx { return self.Body[len(self.Body)-1].Idx1() }
  678. func (self *ReturnStatement) Idx1() file.Idx {
  679. if self.Argument != nil {
  680. return self.Argument.Idx1()
  681. }
  682. return self.Return + 6
  683. }
  684. func (self *SwitchStatement) Idx1() file.Idx { return self.RightBrace + 1 }
  685. func (self *ThrowStatement) Idx1() file.Idx { return self.Argument.Idx1() }
  686. func (self *TryStatement) Idx1() file.Idx {
  687. if self.Finally != nil {
  688. return self.Finally.Idx1()
  689. }
  690. if self.Catch != nil {
  691. return self.Catch.Idx1()
  692. }
  693. return self.Body.Idx1()
  694. }
  695. func (self *VariableStatement) Idx1() file.Idx { return self.List[len(self.List)-1].Idx1() }
  696. func (self *WhileStatement) Idx1() file.Idx { return self.Body.Idx1() }
  697. func (self *WithStatement) Idx1() file.Idx { return self.Body.Idx1() }
  698. func (self *LexicalDeclaration) Idx1() file.Idx { return self.List[len(self.List)-1].Idx1() }
  699. func (self *FunctionDeclaration) Idx1() file.Idx { return self.Function.Idx1() }
  700. func (self *ClassDeclaration) Idx1() file.Idx { return self.Class.Idx1() }
  701. func (self *Binding) Idx1() file.Idx {
  702. if self.Initializer != nil {
  703. return self.Initializer.Idx1()
  704. }
  705. return self.Target.Idx1()
  706. }
  707. func (self *ForLoopInitializerExpression) Idx1() file.Idx { return self.Expression.Idx1() }
  708. func (self *ForLoopInitializerVarDeclList) Idx1() file.Idx { return self.List[len(self.List)-1].Idx1() }
  709. func (self *ForLoopInitializerLexicalDecl) Idx1() file.Idx { return self.LexicalDeclaration.Idx1() }
  710. func (self *PropertyShort) Idx1() file.Idx {
  711. if self.Initializer != nil {
  712. return self.Initializer.Idx1()
  713. }
  714. return self.Name.Idx1()
  715. }
  716. func (self *PropertyKeyed) Idx1() file.Idx { return self.Value.Idx1() }
  717. func (self *ExpressionBody) Idx1() file.Idx { return self.Expression.Idx1() }
  718. func (self *VariableDeclaration) Idx1() file.Idx {
  719. if len(self.List) > 0 {
  720. return self.List[len(self.List)-1].Idx1()
  721. }
  722. return self.Var + 3
  723. }
  724. func (self *FieldDefinition) Idx1() file.Idx {
  725. if self.Initializer != nil {
  726. return self.Initializer.Idx1()
  727. }
  728. return self.Key.Idx1()
  729. }
  730. func (self *MethodDefinition) Idx1() file.Idx {
  731. return self.Body.Idx1()
  732. }
  733. func (self *ClassStaticBlock) Idx1() file.Idx {
  734. return self.Block.Idx1()
  735. }
  736. func (self *YieldExpression) Idx1() file.Idx {
  737. if self.Argument != nil {
  738. return self.Argument.Idx1()
  739. }
  740. return self.Yield + 5
  741. }
  742. func (self *ForDeclaration) Idx1() file.Idx { return self.Target.Idx1() }
  743. func (self *ForIntoVar) Idx1() file.Idx { return self.Binding.Idx1() }
  744. func (self *ForIntoExpression) Idx1() file.Idx { return self.Expression.Idx1() }