node.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  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. }
  325. EmptyStatement struct {
  326. Semicolon file.Idx
  327. }
  328. ExpressionStatement struct {
  329. Expression Expression
  330. }
  331. ForInStatement struct {
  332. For file.Idx
  333. Into ForInto
  334. Source Expression
  335. Body Statement
  336. }
  337. ForOfStatement struct {
  338. For file.Idx
  339. Into ForInto
  340. Source Expression
  341. Body Statement
  342. }
  343. ForStatement struct {
  344. For file.Idx
  345. Initializer ForLoopInitializer
  346. Update Expression
  347. Test Expression
  348. Body Statement
  349. }
  350. IfStatement struct {
  351. If file.Idx
  352. Test Expression
  353. Consequent Statement
  354. Alternate Statement
  355. }
  356. LabelledStatement struct {
  357. Label *Identifier
  358. Colon file.Idx
  359. Statement Statement
  360. }
  361. ReturnStatement struct {
  362. Return file.Idx
  363. Argument Expression
  364. }
  365. SwitchStatement struct {
  366. Switch file.Idx
  367. Discriminant Expression
  368. Default int
  369. Body []*CaseStatement
  370. }
  371. ThrowStatement struct {
  372. Throw file.Idx
  373. Argument Expression
  374. }
  375. TryStatement struct {
  376. Try file.Idx
  377. Body *BlockStatement
  378. Catch *CatchStatement
  379. Finally *BlockStatement
  380. }
  381. VariableStatement struct {
  382. Var file.Idx
  383. List []*Binding
  384. }
  385. LexicalDeclaration struct {
  386. Idx file.Idx
  387. Token token.Token
  388. List []*Binding
  389. }
  390. WhileStatement struct {
  391. While file.Idx
  392. Test Expression
  393. Body Statement
  394. }
  395. WithStatement struct {
  396. With file.Idx
  397. Object Expression
  398. Body Statement
  399. }
  400. FunctionDeclaration struct {
  401. Function *FunctionLiteral
  402. }
  403. ClassDeclaration struct {
  404. Class *ClassLiteral
  405. }
  406. )
  407. // _statementNode
  408. func (*BadStatement) _statementNode() {}
  409. func (*BlockStatement) _statementNode() {}
  410. func (*BranchStatement) _statementNode() {}
  411. func (*CaseStatement) _statementNode() {}
  412. func (*CatchStatement) _statementNode() {}
  413. func (*DebuggerStatement) _statementNode() {}
  414. func (*DoWhileStatement) _statementNode() {}
  415. func (*EmptyStatement) _statementNode() {}
  416. func (*ExpressionStatement) _statementNode() {}
  417. func (*ForInStatement) _statementNode() {}
  418. func (*ForOfStatement) _statementNode() {}
  419. func (*ForStatement) _statementNode() {}
  420. func (*IfStatement) _statementNode() {}
  421. func (*LabelledStatement) _statementNode() {}
  422. func (*ReturnStatement) _statementNode() {}
  423. func (*SwitchStatement) _statementNode() {}
  424. func (*ThrowStatement) _statementNode() {}
  425. func (*TryStatement) _statementNode() {}
  426. func (*VariableStatement) _statementNode() {}
  427. func (*WhileStatement) _statementNode() {}
  428. func (*WithStatement) _statementNode() {}
  429. func (*LexicalDeclaration) _statementNode() {}
  430. func (*FunctionDeclaration) _statementNode() {}
  431. func (*ClassDeclaration) _statementNode() {}
  432. // =========== //
  433. // Declaration //
  434. // =========== //
  435. type (
  436. VariableDeclaration struct {
  437. Var file.Idx
  438. List []*Binding
  439. }
  440. ClassElement interface {
  441. Node
  442. _classElement()
  443. }
  444. FieldDefinition struct {
  445. Idx file.Idx
  446. Key Expression
  447. Initializer Expression
  448. Computed bool
  449. Static bool
  450. }
  451. MethodDefinition struct {
  452. Idx file.Idx
  453. Key Expression
  454. Kind PropertyKind // "method", "get" or "set"
  455. Body *FunctionLiteral
  456. Computed bool
  457. Static bool
  458. }
  459. ClassStaticBlock struct {
  460. Static file.Idx
  461. Block *BlockStatement
  462. Source string
  463. DeclarationList []*VariableDeclaration
  464. }
  465. )
  466. type (
  467. ForLoopInitializer interface {
  468. Node
  469. _forLoopInitializer()
  470. }
  471. ForLoopInitializerExpression struct {
  472. Expression Expression
  473. }
  474. ForLoopInitializerVarDeclList struct {
  475. Var file.Idx
  476. List []*Binding
  477. }
  478. ForLoopInitializerLexicalDecl struct {
  479. LexicalDeclaration LexicalDeclaration
  480. }
  481. ForInto interface {
  482. Node
  483. _forInto()
  484. }
  485. ForIntoVar struct {
  486. Binding *Binding
  487. }
  488. ForDeclaration struct {
  489. Idx file.Idx
  490. IsConst bool
  491. Target BindingTarget
  492. }
  493. ForIntoExpression struct {
  494. Expression Expression
  495. }
  496. )
  497. func (*ForLoopInitializerExpression) _forLoopInitializer() {}
  498. func (*ForLoopInitializerVarDeclList) _forLoopInitializer() {}
  499. func (*ForLoopInitializerLexicalDecl) _forLoopInitializer() {}
  500. func (*ForIntoVar) _forInto() {}
  501. func (*ForDeclaration) _forInto() {}
  502. func (*ForIntoExpression) _forInto() {}
  503. func (*ArrayPattern) _pattern() {}
  504. func (*ArrayPattern) _bindingTarget() {}
  505. func (*ObjectPattern) _pattern() {}
  506. func (*ObjectPattern) _bindingTarget() {}
  507. func (*BadExpression) _bindingTarget() {}
  508. func (*PropertyShort) _property() {}
  509. func (*PropertyKeyed) _property() {}
  510. func (*SpreadElement) _property() {}
  511. func (*Identifier) _bindingTarget() {}
  512. func (*BlockStatement) _conciseBody() {}
  513. func (*ExpressionBody) _conciseBody() {}
  514. func (*FieldDefinition) _classElement() {}
  515. func (*MethodDefinition) _classElement() {}
  516. func (*ClassStaticBlock) _classElement() {}
  517. // ==== //
  518. // Node //
  519. // ==== //
  520. type Program struct {
  521. Body []Statement
  522. DeclarationList []*VariableDeclaration
  523. File *file.File
  524. }
  525. // ==== //
  526. // Idx0 //
  527. // ==== //
  528. func (self *ArrayLiteral) Idx0() file.Idx { return self.LeftBracket }
  529. func (self *ArrayPattern) Idx0() file.Idx { return self.LeftBracket }
  530. func (self *YieldExpression) Idx0() file.Idx { return self.Yield }
  531. func (self *AwaitExpression) Idx0() file.Idx { return self.Await }
  532. func (self *ObjectPattern) Idx0() file.Idx { return self.LeftBrace }
  533. func (self *ParameterList) Idx0() file.Idx { return self.Opening }
  534. func (self *AssignExpression) Idx0() file.Idx { return self.Left.Idx0() }
  535. func (self *BadExpression) Idx0() file.Idx { return self.From }
  536. func (self *BinaryExpression) Idx0() file.Idx { return self.Left.Idx0() }
  537. func (self *BooleanLiteral) Idx0() file.Idx { return self.Idx }
  538. func (self *BracketExpression) Idx0() file.Idx { return self.Left.Idx0() }
  539. func (self *CallExpression) Idx0() file.Idx { return self.Callee.Idx0() }
  540. func (self *ConditionalExpression) Idx0() file.Idx { return self.Test.Idx0() }
  541. func (self *DotExpression) Idx0() file.Idx { return self.Left.Idx0() }
  542. func (self *PrivateDotExpression) Idx0() file.Idx { return self.Left.Idx0() }
  543. func (self *FunctionLiteral) Idx0() file.Idx { return self.Function }
  544. func (self *ClassLiteral) Idx0() file.Idx { return self.Class }
  545. func (self *ArrowFunctionLiteral) Idx0() file.Idx { return self.Start }
  546. func (self *Identifier) Idx0() file.Idx { return self.Idx }
  547. func (self *NewExpression) Idx0() file.Idx { return self.New }
  548. func (self *NullLiteral) Idx0() file.Idx { return self.Idx }
  549. func (self *NumberLiteral) Idx0() file.Idx { return self.Idx }
  550. func (self *ObjectLiteral) Idx0() file.Idx { return self.LeftBrace }
  551. func (self *RegExpLiteral) Idx0() file.Idx { return self.Idx }
  552. func (self *SequenceExpression) Idx0() file.Idx { return self.Sequence[0].Idx0() }
  553. func (self *StringLiteral) Idx0() file.Idx { return self.Idx }
  554. func (self *TemplateElement) Idx0() file.Idx { return self.Idx }
  555. func (self *TemplateLiteral) Idx0() file.Idx { return self.OpenQuote }
  556. func (self *ThisExpression) Idx0() file.Idx { return self.Idx }
  557. func (self *SuperExpression) Idx0() file.Idx { return self.Idx }
  558. func (self *UnaryExpression) Idx0() file.Idx { return self.Idx }
  559. func (self *MetaProperty) Idx0() file.Idx { return self.Idx }
  560. func (self *BadStatement) Idx0() file.Idx { return self.From }
  561. func (self *BlockStatement) Idx0() file.Idx { return self.LeftBrace }
  562. func (self *BranchStatement) Idx0() file.Idx { return self.Idx }
  563. func (self *CaseStatement) Idx0() file.Idx { return self.Case }
  564. func (self *CatchStatement) Idx0() file.Idx { return self.Catch }
  565. func (self *DebuggerStatement) Idx0() file.Idx { return self.Debugger }
  566. func (self *DoWhileStatement) Idx0() file.Idx { return self.Do }
  567. func (self *EmptyStatement) Idx0() file.Idx { return self.Semicolon }
  568. func (self *ExpressionStatement) Idx0() file.Idx { return self.Expression.Idx0() }
  569. func (self *ForInStatement) Idx0() file.Idx { return self.For }
  570. func (self *ForOfStatement) Idx0() file.Idx { return self.For }
  571. func (self *ForStatement) Idx0() file.Idx { return self.For }
  572. func (self *IfStatement) Idx0() file.Idx { return self.If }
  573. func (self *LabelledStatement) Idx0() file.Idx { return self.Label.Idx0() }
  574. func (self *Program) Idx0() file.Idx { return self.Body[0].Idx0() }
  575. func (self *ReturnStatement) Idx0() file.Idx { return self.Return }
  576. func (self *SwitchStatement) Idx0() file.Idx { return self.Switch }
  577. func (self *ThrowStatement) Idx0() file.Idx { return self.Throw }
  578. func (self *TryStatement) Idx0() file.Idx { return self.Try }
  579. func (self *VariableStatement) Idx0() file.Idx { return self.Var }
  580. func (self *WhileStatement) Idx0() file.Idx { return self.While }
  581. func (self *WithStatement) Idx0() file.Idx { return self.With }
  582. func (self *LexicalDeclaration) Idx0() file.Idx { return self.Idx }
  583. func (self *FunctionDeclaration) Idx0() file.Idx { return self.Function.Idx0() }
  584. func (self *ClassDeclaration) Idx0() file.Idx { return self.Class.Idx0() }
  585. func (self *Binding) Idx0() file.Idx { return self.Target.Idx0() }
  586. func (self *ForLoopInitializerExpression) Idx0() file.Idx { return self.Expression.Idx0() }
  587. func (self *ForLoopInitializerVarDeclList) Idx0() file.Idx { return self.List[0].Idx0() }
  588. func (self *ForLoopInitializerLexicalDecl) Idx0() file.Idx { return self.LexicalDeclaration.Idx0() }
  589. func (self *PropertyShort) Idx0() file.Idx { return self.Name.Idx }
  590. func (self *PropertyKeyed) Idx0() file.Idx { return self.Key.Idx0() }
  591. func (self *ExpressionBody) Idx0() file.Idx { return self.Expression.Idx0() }
  592. func (self *VariableDeclaration) Idx0() file.Idx { return self.Var }
  593. func (self *FieldDefinition) Idx0() file.Idx { return self.Idx }
  594. func (self *MethodDefinition) Idx0() file.Idx { return self.Idx }
  595. func (self *ClassStaticBlock) Idx0() file.Idx { return self.Static }
  596. func (self *ForDeclaration) Idx0() file.Idx { return self.Idx }
  597. func (self *ForIntoVar) Idx0() file.Idx { return self.Binding.Idx0() }
  598. func (self *ForIntoExpression) Idx0() file.Idx { return self.Expression.Idx0() }
  599. // ==== //
  600. // Idx1 //
  601. // ==== //
  602. func (self *ArrayLiteral) Idx1() file.Idx { return self.RightBracket + 1 }
  603. func (self *ArrayPattern) Idx1() file.Idx { return self.RightBracket + 1 }
  604. func (self *AssignExpression) Idx1() file.Idx { return self.Right.Idx1() }
  605. func (self *AwaitExpression) Idx1() file.Idx { return self.Argument.Idx1() }
  606. func (self *BadExpression) Idx1() file.Idx { return self.To }
  607. func (self *BinaryExpression) Idx1() file.Idx { return self.Right.Idx1() }
  608. func (self *BooleanLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
  609. func (self *BracketExpression) Idx1() file.Idx { return self.RightBracket + 1 }
  610. func (self *CallExpression) Idx1() file.Idx { return self.RightParenthesis + 1 }
  611. func (self *ConditionalExpression) Idx1() file.Idx { return self.Test.Idx1() }
  612. func (self *DotExpression) Idx1() file.Idx { return self.Identifier.Idx1() }
  613. func (self *PrivateDotExpression) Idx1() file.Idx { return self.Identifier.Idx1() }
  614. func (self *FunctionLiteral) Idx1() file.Idx { return self.Body.Idx1() }
  615. func (self *ClassLiteral) Idx1() file.Idx { return self.RightBrace + 1 }
  616. func (self *ArrowFunctionLiteral) Idx1() file.Idx { return self.Body.Idx1() }
  617. func (self *Identifier) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Name)) }
  618. func (self *NewExpression) Idx1() file.Idx {
  619. if self.ArgumentList != nil {
  620. return self.RightParenthesis + 1
  621. } else {
  622. return self.Callee.Idx1()
  623. }
  624. }
  625. func (self *NullLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + 4) } // "null"
  626. func (self *NumberLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
  627. func (self *ObjectLiteral) Idx1() file.Idx { return self.RightBrace + 1 }
  628. func (self *ObjectPattern) Idx1() file.Idx { return self.RightBrace + 1 }
  629. func (self *ParameterList) Idx1() file.Idx { return self.Closing + 1 }
  630. func (self *RegExpLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
  631. func (self *SequenceExpression) Idx1() file.Idx { return self.Sequence[len(self.Sequence)-1].Idx1() }
  632. func (self *StringLiteral) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
  633. func (self *TemplateElement) Idx1() file.Idx { return file.Idx(int(self.Idx) + len(self.Literal)) }
  634. func (self *TemplateLiteral) Idx1() file.Idx { return self.CloseQuote + 1 }
  635. func (self *ThisExpression) Idx1() file.Idx { return self.Idx + 4 }
  636. func (self *SuperExpression) Idx1() file.Idx { return self.Idx + 5 }
  637. func (self *UnaryExpression) Idx1() file.Idx {
  638. if self.Postfix {
  639. return self.Operand.Idx1() + 2 // ++ --
  640. }
  641. return self.Operand.Idx1()
  642. }
  643. func (self *MetaProperty) Idx1() file.Idx {
  644. return self.Property.Idx1()
  645. }
  646. func (self *BadStatement) Idx1() file.Idx { return self.To }
  647. func (self *BlockStatement) Idx1() file.Idx { return self.RightBrace + 1 }
  648. func (self *BranchStatement) Idx1() file.Idx { return self.Idx }
  649. func (self *CaseStatement) Idx1() file.Idx { return self.Consequent[len(self.Consequent)-1].Idx1() }
  650. func (self *CatchStatement) Idx1() file.Idx { return self.Body.Idx1() }
  651. func (self *DebuggerStatement) Idx1() file.Idx { return self.Debugger + 8 }
  652. func (self *DoWhileStatement) Idx1() file.Idx { return self.Test.Idx1() }
  653. func (self *EmptyStatement) Idx1() file.Idx { return self.Semicolon + 1 }
  654. func (self *ExpressionStatement) Idx1() file.Idx { return self.Expression.Idx1() }
  655. func (self *ForInStatement) Idx1() file.Idx { return self.Body.Idx1() }
  656. func (self *ForOfStatement) Idx1() file.Idx { return self.Body.Idx1() }
  657. func (self *ForStatement) Idx1() file.Idx { return self.Body.Idx1() }
  658. func (self *IfStatement) Idx1() file.Idx {
  659. if self.Alternate != nil {
  660. return self.Alternate.Idx1()
  661. }
  662. return self.Consequent.Idx1()
  663. }
  664. func (self *LabelledStatement) Idx1() file.Idx { return self.Colon + 1 }
  665. func (self *Program) Idx1() file.Idx { return self.Body[len(self.Body)-1].Idx1() }
  666. func (self *ReturnStatement) Idx1() file.Idx { return self.Return + 6 }
  667. func (self *SwitchStatement) Idx1() file.Idx { return self.Body[len(self.Body)-1].Idx1() }
  668. func (self *ThrowStatement) Idx1() file.Idx { return self.Argument.Idx1() }
  669. func (self *TryStatement) Idx1() file.Idx {
  670. if self.Finally != nil {
  671. return self.Finally.Idx1()
  672. }
  673. if self.Catch != nil {
  674. return self.Catch.Idx1()
  675. }
  676. return self.Body.Idx1()
  677. }
  678. func (self *VariableStatement) Idx1() file.Idx { return self.List[len(self.List)-1].Idx1() }
  679. func (self *WhileStatement) Idx1() file.Idx { return self.Body.Idx1() }
  680. func (self *WithStatement) Idx1() file.Idx { return self.Body.Idx1() }
  681. func (self *LexicalDeclaration) Idx1() file.Idx { return self.List[len(self.List)-1].Idx1() }
  682. func (self *FunctionDeclaration) Idx1() file.Idx { return self.Function.Idx1() }
  683. func (self *ClassDeclaration) Idx1() file.Idx { return self.Class.Idx1() }
  684. func (self *Binding) Idx1() file.Idx {
  685. if self.Initializer != nil {
  686. return self.Initializer.Idx1()
  687. }
  688. return self.Target.Idx1()
  689. }
  690. func (self *ForLoopInitializerExpression) Idx1() file.Idx { return self.Expression.Idx1() }
  691. func (self *ForLoopInitializerVarDeclList) Idx1() file.Idx { return self.List[len(self.List)-1].Idx1() }
  692. func (self *ForLoopInitializerLexicalDecl) Idx1() file.Idx { return self.LexicalDeclaration.Idx1() }
  693. func (self *PropertyShort) Idx1() file.Idx {
  694. if self.Initializer != nil {
  695. return self.Initializer.Idx1()
  696. }
  697. return self.Name.Idx1()
  698. }
  699. func (self *PropertyKeyed) Idx1() file.Idx { return self.Value.Idx1() }
  700. func (self *ExpressionBody) Idx1() file.Idx { return self.Expression.Idx1() }
  701. func (self *VariableDeclaration) Idx1() file.Idx {
  702. if len(self.List) > 0 {
  703. return self.List[len(self.List)-1].Idx1()
  704. }
  705. return self.Var + 3
  706. }
  707. func (self *FieldDefinition) Idx1() file.Idx {
  708. if self.Initializer != nil {
  709. return self.Initializer.Idx1()
  710. }
  711. return self.Key.Idx1()
  712. }
  713. func (self *MethodDefinition) Idx1() file.Idx {
  714. return self.Body.Idx1()
  715. }
  716. func (self *ClassStaticBlock) Idx1() file.Idx {
  717. return self.Block.Idx1()
  718. }
  719. func (self *YieldExpression) Idx1() file.Idx {
  720. if self.Argument != nil {
  721. return self.Argument.Idx1()
  722. }
  723. return self.Yield + 5
  724. }
  725. func (self *ForDeclaration) Idx1() file.Idx { return self.Target.Idx1() }
  726. func (self *ForIntoVar) Idx1() file.Idx { return self.Binding.Idx1() }
  727. func (self *ForIntoExpression) Idx1() file.Idx { return self.Expression.Idx1() }