@@ -773,28 +773,22 @@ exports.Block = class Block extends Base
773
773
return nodes[0 ] if nodes .length is 1 and nodes[0 ] instanceof Block
774
774
new Block nodes
775
775
776
- # Wraps a non-statement expression’s AST in an `ExpressionStatement` AST node.
777
- asExpressionStatementAst : (ast ) ->
778
- Object .assign
779
- type : ' ExpressionStatement'
780
- expression : ast
781
- ,
782
- extractAstLocationData ast
783
-
784
- # Returns the AST for a given top-level expression: either the expression's
785
- # AST as-is (if the expression is a statement) or the expression's AST wrapped
786
- # in an `ExpressionStatement` AST node.
787
- getExpressionAst : (expression ) ->
788
- ast = expression .ast ()
789
- # return ast if expression.isStatement o
790
- @ asExpressionStatementAst ast
791
-
792
- bodyToAst : ->
793
- @ getExpressionAst (expression) for expression in @expressions
794
-
795
776
astType : -> ' Program'
796
777
797
- astProperties : ->
778
+ astProperties : (o ) ->
779
+ body = []
780
+ for expression in @expressions
781
+ # If an expression is a statement, it can be added to the body as is.
782
+ if expression .isStatement o
783
+ body .push expression .ast ()
784
+ # Otherwise, we need to wrap it in an `ExpressionStatement` AST node.
785
+ else
786
+ body .push Object .assign
787
+ type : ' ExpressionStatement'
788
+ expression : expression .ast ()
789
+ ,
790
+ expression .astLocationData ()
791
+
798
792
return
799
793
# For now, we’re not including `sourceType` on the `Program` AST node.
800
794
# Its value could be either `'script'` or `'module'`, and there’s no way
@@ -809,8 +803,8 @@ exports.Block = class Block extends Base
809
803
# then CoffeeScript can copy Node’s algorithm.
810
804
811
805
# sourceType: 'module'
812
- body : @ bodyToAst ()
813
- directives : []
806
+ body : body
807
+ directives : [] # Directives like `'use strict'` are coming soon.
814
808
815
809
# ### Literal
816
810
@@ -4756,14 +4750,6 @@ makeDelimitedLiteral = (body, options = {}) ->
4756
4750
when other then (if options. double then "\\ #{ other} " else other)
4757
4751
"#{ options .delimiter }#{ body}#{ options .delimiter } "
4758
4752
4759
- # Extract location data fields from an AST node.
4760
- extractAstLocationData = (ast) ->
4761
- return
4762
- loc: ast. loc
4763
- range: ast. range
4764
- start: ast. start
4765
- end: ast. end
4766
-
4767
4753
# Helpers for `mergeLocationData` and `mergeAstLocationData` below.
4768
4754
lesser = (a, b) -> if a < b then a else b
4769
4755
greater = (a, b) -> if a > b then a else b
0 commit comments