node.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  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. ArrayLiteral struct {
  47. LeftBracket file.Idx
  48. RightBracket file.Idx
  49. Value []Expression
  50. }
  51. ArrayPattern struct {
  52. LeftBracket file.Idx
  53. RightBracket file.Idx
  54. Elements []Expression
  55. Rest Expression
  56. }
  57. AssignExpression struct {
  58. Operator token.Token
  59. Left Expression
  60. Right Expression
  61. }
  62. BadExpression struct {
  63. From file.Idx
  64. To file.Idx
  65. }
  66. BinaryExpression struct {
  67. Operator token.Token
  68. Left Expression
  69. Right Expression
  70. Comparison bool
  71. }
  72. BooleanLiteral struct {
  73. Idx file.Idx
  74. Literal string
  75. Value bool
  76. }
  77. BracketExpression struct {
  78. Left Expression
  79. Member Expression
  80. LeftBracket file.Idx
  81. RightBracket file.Idx
  82. }
  83. CallExpression struct {
  84. Callee Expression
  85. LeftParenthesis file.Idx
  86. ArgumentList []Expression
  87. RightParenthesis file.Idx
  88. }
  89. ConditionalExpression struct {
  90. Test Expression
  91. Consequent Expression
  92. Alternate Expression
  93. }
  94. DotExpression struct {
  95. Left Expression
  96. Identifier Identifier
  97. }
  98. FunctionLiteral struct {
  99. Function file.Idx
  100. Name *Identifier
  101. ParameterList *ParameterList
  102. Body *BlockStatement
  103. Source string
  104. DeclarationList []*VariableDeclaration
  105. }
  106. ConciseBody interface {
  107. Node
  108. _conciseBody()
  109. }
  110. ExpressionBody struct {
  111. Expression Expression
  112. }
  113. ArrowFunctionLiteral struct {
  114. Start file.Idx
  115. ParameterList *ParameterList
  116. Body ConciseBody
  117. Source string
  118. DeclarationList []*VariableDeclaration
  119. }
  120. Identifier struct {
  121. Name unistring.String
  122. Idx file.Idx
  123. }
  124. NewExpression struct {
  125. New file.Idx
  126. Callee Expression
  127. LeftParenthesis file.Idx
  128. ArgumentList []Expression
  129. RightParenthesis file.Idx
  130. }
  131. NullLiteral struct {
  132. Idx file.Idx
  133. Literal string
  134. }
  135. NumberLiteral struct {
  136. Idx file.Idx
  137. Literal string
  138. Value interface{}
  139. }
  140. BigIntLiteral struct {
  141. Idx file.Idx
  142. Literal string
  143. Value interface{}
  144. }
  145. ObjectLiteral struct {
  146. LeftBrace file.Idx
  147. RightBrace file.Idx
  148. Value []Property
  149. }
  150. ObjectPattern struct {
  151. LeftBrace file.Idx
  152. RightBrace file.Idx
  153. Properties []Property
  154. Rest Expression
  155. }
  156. ParameterList struct {
  157. Opening file.Idx
  158. List []*Binding
  159. Rest Expression
  160. Closing file.Idx
  161. }
  162. Property interface {
  163. Expression
  164. _property()
  165. }
  166. PropertyShort struct {
  167. Name Identifier
  168. Initializer Expression
  169. }
  170. PropertyKeyed struct {
  171. Key Expression
  172. Kind PropertyKind
  173. Value Expression
  174. }
  175. SpreadElement struct {
  176. Expression
  177. }
  178. RegExpLiteral struct {
  179. Idx file.Idx
  180. Literal string
  181. Pattern string
  182. Flags string
  183. }
  184. SequenceExpression struct {
  185. Sequence []Expression
  186. }
  187. StringLiteral struct {
  188. Idx file.Idx
  189. Literal string
  190. Value unistring.String
  191. }
  192. TemplateElement struct {
  193. Idx file.Idx
  194. Literal string
  195. Parsed unistring.String
  196. Valid bool
  197. }
  198. TemplateLiteral struct {
  199. OpenQuote file.Idx
  200. CloseQuote file.Idx
  201. Tag Expression
  202. Elements []*TemplateElement
  203. Expressions []Expression
  204. }
  205. ThisExpression struct {
  206. Idx file.Idx
  207. }
  208. UnaryExpression struct {
  209. Operator token.Token
  210. Idx file.Idx // If a prefix operation
  211. Operand Expression
  212. Postfix bool
  213. }
  214. MetaProperty struct {
  215. Meta, Property *Identifier
  216. Idx file.Idx
  217. }
  218. )
  219. // _expressionNode
  220. func (*ArrayLiteral) _expressionNode() {}
  221. func (*AssignExpression) _expressionNode() {}
  222. func (*BadExpression) _expressionNode() {}
  223. func (*BinaryExpression) _expressionNode() {}
  224. func (*BooleanLiteral) _expressionNode() {}
  225. func (*BracketExpression) _expressionNode() {}
  226. func (*CallExpression) _expressionNode() {}
  227. func (*ConditionalExpression) _expressionNode() {}
  228. func (*DotExpression) _expressionNode() {}
  229. func (*FunctionLiteral) _expressionNode() {}
  230. func (*ArrowFunctionLiteral) _expressionNode() {}
  231. func (*Identifier) _expressionNode() {}
  232. func (*NewExpression) _expressionNode() {}
  233. func (*NullLiteral) _expressionNode() {}
  234. func (*NumberLiteral) _expressionNode() {}
  235. func (*BigIntLiteral) _expressionNode() {}
  236. func (*ObjectLiteral) _expressionNode() {}
  237. func (*RegExpLiteral) _expressionNode() {}
  238. func (*SequenceExpression) _expressionNode() {}
  239. func (*StringLiteral) _expressionNode() {}
  240. func (*TemplateLiteral) _expressionNode() {}
  241. func (*ThisExpression) _expressionNode() {}
  242. func (*UnaryExpression) _expressionNode() {}
  243. func (*MetaProperty) _expressionNode() {}
  244. func (*ObjectPattern) _expressionNode() {}
  245. func (*ArrayPattern) _expressionNode() {}
  246. func (*Binding) _expressionNode() {}
  247. func (*PropertyShort) _expressionNode() {}
  248. func (*PropertyKeyed) _expressionNode() {}
  249. // ========= //
  250. // Statement //
  251. // ========= //
  252. type (
  253. // All statement nodes implement the Statement interface.
  254. Statement interface {
  255. Node
  256. _statementNode()
  257. }
  258. BadStatement struct {
  259. From file.Idx
  260. To file.Idx
  261. }
  262. BlockStatement struct {
  263. LeftBrace file.Idx
  264. List []Statement
  265. RightBrace file.Idx
  266. }
  267. BranchStatement struct {
  268. Idx file.Idx
  269. Token token.Token
  270. Label *Identifier
  271. }
  272. CaseStatement struct {
  273. Case file.Idx
  274. Test Expression
  275. Consequent []Statement
  276. }
  277. CatchStatement struct {
  278. Catch file.Idx
  279. Parameter BindingTarget
  280. Body *BlockStatement
  281. }
  282. DebuggerStatement struct {
  283. Debugger file.Idx
  284. }
  285. DoWhileStatement struct {
  286. Do file.Idx
  287. Test Expression
  288. Body Statement
  289. }
  290. EmptyStatement struct {
  291. Semicolon file.Idx
  292. }
  293. ExpressionStatement struct {
  294. Expression Expression
  295. }
  296. ForInStatement struct {
  297. For file.Idx
  298. Into ForInto
  299. Source Expression
  300. Body Statement
  301. }
  302. ForOfStatement struct {
  303. For file.Idx
  304. Into ForInto
  305. Source Expression
  306. Body Statement
  307. }
  308. ForStatement struct {
  309. For file.Idx
  310. Initializer ForLoopInitializer
  311. Update Expression
  312. Test Expression
  313. Body Statement
  314. }
  315. IfStatement struct {
  316. If file.Idx
  317. Test Expression
  318. Consequent Statement
  319. Alternate Statement
  320. }
  321. LabelledStatement struct {
  322. Label *Identifier
  323. Colon file.Idx
  324. Statement Statement
  325. }
  326. ReturnStatement struct {
  327. Return file.Idx
  328. Argument Expression
  329. }
  330. SwitchStatement struct {
  331. Switch file.Idx
  332. Discriminant Expression
  333. Default int
  334. Body []*CaseStatement
  335. }
  336. ThrowStatement struct {
  337. Throw file.Idx
  338. Argument Expression
  339. }
  340. TryStatement struct {
  341. Try file.Idx
  342. Body *BlockStatement
  343. Catch *CatchStatement
  344. Finally *BlockStatement
  345. }
  346. VariableStatement struct {
  347. Var file.Idx
  348. List []*Binding
  349. }
  350. LexicalDeclaration struct {
  351. Idx file.Idx
  352. Token token.Token
  353. List []*Binding
  354. }
  355. WhileStatement struct {
  356. While file.Idx
  357. Test Expression
  358. Body Statement
  359. }
  360. WithStatement struct {
  361. With file.Idx
  362. Object Expression
  363. Body Statement
  364. }
  365. FunctionDeclaration struct {
  366. Function *FunctionLiteral
  367. }
  368. )
  369. // _statementNode
  370. func (*BadStatement) _statementNode() {}
  371. func (*BlockStatement) _statementNode() {}
  372. func (*BranchStatement) _statementNode() {}
  373. func (*CaseStatement) _statementNode() {}
  374. func (*CatchStatement) _statementNode() {}
  375. func (*DebuggerStatement) _statementNode() {}
  376. func (*DoWhileStatement) _statementNode() {}
  377. func (*EmptyStatement) _statementNode() {}
  378. func (*ExpressionStatement) _statementNode() {}
  379. func (*ForInStatement) _statementNode() {}
  380. func (*ForOfStatement) _statementNode() {}
  381. func (*ForStatement) _statementNode() {}
  382. func (*IfStatement) _statementNode() {}
  383. func (*LabelledStatement) _statementNode() {}
  384. func (*ReturnStatement) _statementNode() {}
  385. func (*SwitchStatement) _statementNode() {}
  386. func (*ThrowStatement) _statementNode() {}
  387. func (*TryStatement) _statementNode() {}
  388. func (*VariableStatement) _statementNode() {}
  389. func (*WhileStatement) _statementNode() {}
  390. func (*WithStatement) _statementNode() {}
  391. func (*LexicalDeclaration) _statementNode() {}
  392. func (*FunctionDeclaration) _statementNode() {}
  393. // =========== //
  394. // Declaration //
  395. // =========== //
  396. type (
  397. VariableDeclaration struct {
  398. Var file.Idx
  399. List []*Binding
  400. }
  401. )
  402. type (
  403. ForLoopInitializer interface {
  404. _forLoopInitializer()
  405. }
  406. ForLoopInitializerExpression struct {
  407. Expression Expression
  408. }
  409. ForLoopInitializerVarDeclList struct {
  410. Var file.Idx
  411. List []*Binding
  412. }
  413. ForLoopInitializerLexicalDecl struct {
  414. LexicalDeclaration LexicalDeclaration
  415. }
  416. ForInto interface {
  417. _forInto()
  418. }
  419. ForIntoVar struct {
  420. Binding *Binding
  421. }
  422. ForDeclaration struct {
  423. Idx file.Idx
  424. IsConst bool
  425. Target BindingTarget
  426. }
  427. ForIntoExpression struct {
  428. Expression Expression
  429. }
  430. )
  431. func (*ForLoopInitializerExpression) _forLoopInitializer() {}
  432. func (*ForLoopInitializerVarDeclList) _forLoopInitializer() {}
  433. func (*ForLoopInitializerLexicalDecl) _forLoopInitializer() {}
  434. func (*ForIntoVar) _forInto() {}
  435. func (*ForDeclaration) _forInto() {}
  436. func (*ForIntoExpression) _forInto() {}
  437. func (*ArrayPattern) _pattern() {}
  438. func (*ArrayPattern) _bindingTarget() {}
  439. func (*ObjectPattern) _pattern() {}
  440. func (*ObjectPattern) _bindingTarget() {}
  441. func (*BadExpression) _bindingTarget() {}
  442. func (*PropertyShort) _property() {}
  443. func (*PropertyKeyed) _property() {}
  444. func (*SpreadElement) _property() {}
  445. func (*Identifier) _bindingTarget() {}
  446. func (*BlockStatement) _conciseBody() {}
  447. func (*ExpressionBody) _conciseBody() {}
  448. // ==== //
  449. // Node //
  450. // ==== //
  451. type Program struct {
  452. Body []Statement
  453. DeclarationList []*VariableDeclaration
  454. File *file.File
  455. }
  456. // ==== //
  457. // Idx0 //
  458. // ==== //
  459. func (self *ArrayLiteral) Idx0() file.Idx { return self.LeftBracket }
  460. func (self *ArrayPattern) Idx0() file.Idx { return self.LeftBracket }
  461. func (self *ObjectPattern) Idx0() file.Idx { return self.LeftBrace }
  462. func (self *AssignExpression) Idx0() file.Idx { return self.Left.Idx0() }
  463. func (self *BadExpression) Idx0() file.Idx { return self.From }
  464. func (self *BinaryExpression) Idx0() file.Idx { return self.Left.Idx0() }
  465. func (self *BooleanLiteral) Idx0() file.Idx { return self.Idx }
  466. func (self *BracketExpression) Idx0() file.Idx { return self.Left.Idx0() }
  467. func (self *CallExpression) Idx0() file.Idx { return self.Callee.Idx0() }
  468. func (self *ConditionalExpression) Idx0() file.Idx { return self.Test.Idx0() }
  469. func (self *DotExpression) Idx0() file.Idx { return self.Left.Idx0() }
  470. func (self *FunctionLiteral) Idx0() file.Idx { return self.Function }
  471. func (self *ArrowFunctionLiteral) Idx0() file.Idx { return self.Start }
  472. func (self *Identifier) Idx0() file.Idx { return self.Idx }
  473. func (self *NewExpression) Idx0() file.Idx { return self.New }
  474. func (self *NullLiteral) Idx0() file.Idx { return self.Idx }
  475. func (self *NumberLiteral) Idx0() file.Idx { return self.Idx }
  476. func (self *BigIntLiteral) Idx0() file.Idx { return self.Idx }
  477. func (self *ObjectLiteral) Idx0() file.Idx { return self.LeftBrace }
  478. func (self *RegExpLiteral) Idx0() file.Idx { return self.Idx }
  479. func (self *SequenceExpression) Idx0() file.Idx { return self.Sequence[0].Idx0() }
  480. func (self *StringLiteral) Idx0() file.Idx { return self.Idx }
  481. func (self *TemplateLiteral) Idx0() file.Idx { return self.OpenQuote }
  482. func (self *ThisExpression) Idx0() file.Idx { return self.Idx }
  483. func (self *UnaryExpression) Idx0() file.Idx { return self.Idx }
  484. func (self *MetaProperty) Idx0() file.Idx { return self.Idx }
  485. func (self *BadStatement) Idx0() file.Idx { return self.From }
  486. func (self *BlockStatement) Idx0() file.Idx { return self.LeftBrace }
  487. func (self *BranchStatement) Idx0() file.Idx { return self.Idx }
  488. func (self *CaseStatement) Idx0() file.Idx { return self.Case }
  489. func (self *CatchStatement) Idx0() file.Idx { return self.Catch }
  490. func (self *DebuggerStatement) Idx0() file.Idx { return self.Debugger }
  491. func (self *DoWhileStatement) Idx0() file.Idx { return self.Do }
  492. func (self *EmptyStatement) Idx0() file.Idx { return self.Semicolon }
  493. func (self *ExpressionStatement) Idx0() file.Idx { return self.Expression.Idx0() }
  494. func (self *ForInStatement) Idx0() file.Idx { return self.For }
  495. func (self *ForOfStatement) Idx0() file.Idx { return self.For }
  496. func (self *ForStatement) Idx0() file.Idx { return self.For }
  497. func (self *IfStatement) Idx0() file.Idx { return self.If }
  498. func (self *LabelledStatement) Idx0() file.Idx { return self.Label.Idx0() }
  499. func (self *Program) Idx0() file.Idx { return self.Body[0].Idx0() }
  500. func (self *ReturnStatement) Idx0() file.Idx { return self.Return }
  501. func (self *SwitchStatement) Idx0() file.Idx { return self.Switch }
  502. func (self *ThrowStatement) Idx0() file.Idx { return self.Throw }
  503. func (self *TryStatement) Idx0() file.Idx { return self.Try }
  504. func (self *VariableStatement) Idx0() file.Idx { return self.Var }
  505. func (self *WhileStatement) Idx0() file.Idx { return self.While }
  506. func (self *WithStatement) Idx0() file.Idx { return self.With }
  507. func (self *LexicalDeclaration) Idx0() file.Idx { return self.Idx }
  508. func (self *FunctionDeclaration) Idx0() file.Idx { return self.Function.Idx0() }
  509. func (self *Binding) Idx0() file.Idx { return self.Target.Idx0() }
  510. func (self *ForLoopInitializerVarDeclList) Idx0() file.Idx { return self.List[0].Idx0() }
  511. func (self *PropertyShort) Idx0() file.Idx { return self.Name.Idx }
  512. func (self *PropertyKeyed) Idx0() file.Idx { return self.Key.Idx0() }
  513. func (self *ExpressionBody) Idx0() file.Idx { return self.Expression.Idx0() }
  514. // ==== //
  515. // Idx1 //
  516. // ==== //
  517. func (self *ArrayLiteral) Idx1() file.Idx { return self.RightBracket + 1 }
  518. func (self *ArrayPattern) Idx1() file.Idx { return self.RightBracket + 1 }
  519. func (self *AssignExpression) Idx1() file.Idx { return self.Right.Idx1() }
  520. func (self *BadExpression) Idx1() file.Idx { return self.To }
  521. func (self *BinaryExpression) Idx1() file.Idx { return self.Right.Idx1() }
  522. func (self *BooleanLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
  523. func (self *BracketExpression) Idx1() file.Idx { return self.RightBracket + 1 }
  524. func (self *CallExpression) Idx1() file.Idx { return self.RightParenthesis + 1 }
  525. func (self *ConditionalExpression) Idx1() file.Idx { return self.Test.Idx1() }
  526. func (self *DotExpression) Idx1() file.Idx { return self.Identifier.Idx1() }
  527. func (self *FunctionLiteral) Idx1() file.Idx { return self.Body.Idx1() }
  528. func (self *ArrowFunctionLiteral) Idx1() file.Idx { return self.Body.Idx1() }
  529. func (self *Identifier) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Name)) }
  530. func (self *NewExpression) Idx1() file.Idx { return self.RightParenthesis + 1 }
  531. func (self *NullLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + 4) } // "null"
  532. func (self *NumberLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
  533. func (self *BigIntLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
  534. func (self *ObjectLiteral) Idx1() file.Idx { return self.RightBrace + 1 }
  535. func (self *ObjectPattern) Idx1() file.Idx { return self.RightBrace + 1 }
  536. func (self *RegExpLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
  537. func (self *SequenceExpression) Idx1() file.Idx { return self.Sequence[len(self.Sequence)-1].Idx1() }
  538. func (self *StringLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
  539. func (self *TemplateLiteral) Idx1() file.Idx { return self.CloseQuote + 1 }
  540. func (self *ThisExpression) Idx1() file.Idx { return self.Idx + 4 }
  541. func (self *UnaryExpression) Idx1() file.Idx {
  542. if self.Postfix {
  543. return self.Operand.Idx1() + 2 // ++ --
  544. }
  545. return self.Operand.Idx1()
  546. }
  547. func (self *MetaProperty) Idx1() file.Idx {
  548. return self.Property.Idx1()
  549. }
  550. func (self *BadStatement) Idx1() file.Idx { return self.To }
  551. func (self *BlockStatement) Idx1() file.Idx { return self.RightBrace + 1 }
  552. func (self *BranchStatement) Idx1() file.Idx { return self.Idx }
  553. func (self *CaseStatement) Idx1() file.Idx { return self.Consequent[len(self.Consequent)-1].Idx1() }
  554. func (self *CatchStatement) Idx1() file.Idx { return self.Body.Idx1() }
  555. func (self *DebuggerStatement) Idx1() file.Idx { return self.Debugger + 8 }
  556. func (self *DoWhileStatement) Idx1() file.Idx { return self.Test.Idx1() }
  557. func (self *EmptyStatement) Idx1() file.Idx { return self.Semicolon + 1 }
  558. func (self *ExpressionStatement) Idx1() file.Idx { return self.Expression.Idx1() }
  559. func (self *ForInStatement) Idx1() file.Idx { return self.Body.Idx1() }
  560. func (self *ForOfStatement) Idx1() file.Idx { return self.Body.Idx1() }
  561. func (self *ForStatement) Idx1() file.Idx { return self.Body.Idx1() }
  562. func (self *IfStatement) Idx1() file.Idx {
  563. if self.Alternate != nil {
  564. return self.Alternate.Idx1()
  565. }
  566. return self.Consequent.Idx1()
  567. }
  568. func (self *LabelledStatement) Idx1() file.Idx { return self.Colon + 1 }
  569. func (self *Program) Idx1() file.Idx { return self.Body[len(self.Body)-1].Idx1() }
  570. func (self *ReturnStatement) Idx1() file.Idx { return self.Return + 6 }
  571. func (self *SwitchStatement) Idx1() file.Idx { return self.Body[len(self.Body)-1].Idx1() }
  572. func (self *ThrowStatement) Idx1() file.Idx { return self.Argument.Idx1() }
  573. func (self *TryStatement) Idx1() file.Idx {
  574. if self.Finally != nil {
  575. return self.Finally.Idx1()
  576. }
  577. if self.Catch != nil {
  578. return self.Catch.Idx1()
  579. }
  580. return self.Body.Idx1()
  581. }
  582. func (self *VariableStatement) Idx1() file.Idx { return self.List[len(self.List)-1].Idx1() }
  583. func (self *WhileStatement) Idx1() file.Idx { return self.Body.Idx1() }
  584. func (self *WithStatement) Idx1() file.Idx { return self.Body.Idx1() }
  585. func (self *LexicalDeclaration) Idx1() file.Idx { return self.List[len(self.List)-1].Idx1() }
  586. func (self *FunctionDeclaration) Idx1() file.Idx { return self.Function.Idx1() }
  587. func (self *Binding) Idx1() file.Idx {
  588. if self.Initializer != nil {
  589. return self.Initializer.Idx1()
  590. }
  591. return self.Target.Idx1()
  592. }
  593. func (self *ForLoopInitializerVarDeclList) Idx1() file.Idx { return self.List[len(self.List)-1].Idx1() }
  594. func (self *PropertyShort) Idx1() file.Idx {
  595. if self.Initializer != nil {
  596. return self.Initializer.Idx1()
  597. }
  598. return self.Name.Idx1()
  599. }
  600. func (self *PropertyKeyed) Idx1() file.Idx { return self.Value.Idx1() }
  601. func (self *ExpressionBody) Idx1() file.Idx { return self.Expression.Idx1() }