node.go 20 KB

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