node.go 19 KB

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