node.go 23 KB

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