Lines Matching +refs:expand +refs:context +refs:for +refs:serializable

1 # `nodes.coffee` contains all of the node classes for the syntax tree. Most
21 # Constant functions for nodes that don’t need customization.
41 # This is only intended for debugging.
46 (fragment.code for fragment in fragments).join('')
50 # The **Base** is the abstract base class for all nodes in the syntax tree.
52 # code generation for that node. To compile a node to JavaScript,
64 # Occasionally a node is compiled multiple times, for example to get the name
67 # so that they’re preserved for a later `compile` call that will result in
92 # Common logic for determining whether to wrap this node in a closure before
164 for comment in node.comments when comment not in @compiledComments
169 # Otherwise attach comment fragments to their closest fragment for now,
179 # `compileToFragments` method has logic for outputting comments.
214 # methods to store their result for later replacing the `target` node, which is returned by the
235 # Note that this is overridden for smarter behavior for
265 # Debugging representation of the node, for inspecting the parse tree.
280 # as closely as possible, for improved interoperability with other tools.
286 # Create serializable representation of this node.
301 # `.ast()` for child nodes and those nodes would need the return logic from `makeReturn`
314 # separate methods for returning each category, that we merge together here.
336 for attr in @children when @[attr]
337 for child in flatten [@[attr]]
346 # `replaceInContext` will traverse children looking for a node for which `match` returns
350 for attr in @children when children = @[attr]
352 for child, i in children
382 # `true` for are things that can’t be used as expressions. There are some
409 # also cases where we might not need to cache but where we want to, for
411 # for brevity.
464 for fragments, i in fragmentsList
471 # A **HoistTargetNode** represents the output location in the node tree for a hoisted node.
475 @expand = (fragments) ->
476 for fragment, i in fragments by -1 when fragment.fragments
477 fragments[i..i] = @expand fragment.fragments
522 # better not to generate them in the first place, but for now, clean up
538 o.scope.parameter name for name in o.locals or []
542 for commentToken in (@allCommentTokens ? []) when not commentToken.heregex
547 comment.ast() for comment in @allComments
599 for exp in @expressions when exp.isStatement o
604 for exp in @expressions
645 for node, index in @expressions
682 HoistTarget.expand fragments
685 # Compile the expressions body for the contents of a function, with
690 for exp, i in @expressions
709 for declaredVariable, declaredVariablesIndex in declaredVariables
724 for fragment, fragmentIndex in fragments
729 # to insert comments before, and use that indentation level for our
733 # search for a `code` property that begins with at least two spaces.
735 for pastFragment in fragments[0...(fragmentIndex + 1)] by -1
743 for commentFragment in fragment.precedingComments
749 for pastFragment, pastFragmentIndex in fragments[0...(fragmentIndex + 1)] by -1
783 for upcomingFragment in fragments[fragmentIndex...]
806 for commentFragment in fragment.followingComments
812 for upcomingFragment, upcomingFragmentIndex in fragments[fragmentIndex...]
862 for expression in @expressions
883 # for CoffeeScript to always know which it should be. The presence of an
890 # or `script`, and so if Node figures out a way to do so for `.js` files
915 # `Literal` is a base class for static values that can be passed through
935 # This is only intended for debugging.
1133 for heregexCommentToken in @heregexCommentTokens
1220 code = if o.scope.method?.bound then o.scope.method.context else @value
1290 for fragment in answer
1312 # Parent class for `YieldReturn`/`AwaitReturn`.
1381 # Some boolean checks for the benefit of other nodes.
1393 for node in @properties.concat @base
1430 # We cache them separately for compiling complex expressions.
1466 for prop in props
1478 for prop, i in @properties when prop.soak
1501 # Get all properties except the last one; for a `Value` with only one
1504 # Create the `object` that becomes the new “base” for the split-off final
1508 # for source maps or later conversion into AST location data.
1524 for property in @properties when property.soak
1582 @error "the only valid meta property for new is new.target"
1585 @error "the only valid meta property for import is import.meta"
1614 for line in @content.split '\n'
1743 for object in arr.objects
1759 for property in base.properties
1782 for attribute in @attributes
1788 attribute.ast(o) for attribute in @attributes
1805 # Node for a JSX element
1920for element in @content.unwrapAll().extractElements o, includeInterpolationWrappers: yes, isJsx: y…
1943 … child.ast(o) for child in children when not (child instanceof JSXText and child.value.length is 0)
1963 # Node for a function invocation.
1981 # part of `RegexWithInterpolations`, so for that case move any comments to
1990 # account for a newly-discovered `new` operator to the left of us. This
2050 for call in list.reverse()
2072 argCode = (arg for arg in (@args || []) when arg instanceof Code)
2077 for arg, argIndex in @args
2114 arguments: arg.ast(o, LEVEL_LIST) for arg in @args
2164 # the `method` property name gets compiled for the first time here, and
2170 # that they’re there for the later compilation.
2214 for heregexCommentToken in @heregexCommentTokens
2254 # A `.` access into a property of a value, or the `::` shorthand for
2273 # Babel doesn’t have an AST node for `Access`, but rather just includes
2294 # Babel doesn’t have an AST node for `Index`, but rather just includes
2297 # `property` is an Index means that `computed` is `true` for the
2304 # to specify a range for comprehensions, or as a value, to be expanded into the
2328 # When compiled normally, the range returns the contents of the *for loop*
2390 # When used as a value, expand the range into the equivalent array.
2411 [@makeCode "(function() {#{pre}\n#{idt}for (#{body})#{post}}).apply(this#{args ? ''})"]
2471 for prop in @properties
2472 # Check for reserved words.
2477 prop.context is 'object' and
2487 return yes for prop in @properties when prop instanceof Splat
2503 for node in props when node instanceof Value
2514 for prop in @properties
2515 if prop instanceof Assign and prop.context is 'object'
2520 for prop, i in props
2531 key = if prop instanceof Assign and prop.context is 'object'
2539 key.error 'invalid object key' if prop.context is 'object' or not key.this
2568 splatProps = (i for prop, i in props when prop instanceof Splat)
2573 for prop in @properties when prop.assigns name then return yes
2577 for prop in @properties
2578 prop = prop.value if prop instanceof Assign and prop.context is 'object'
2584 {variable, context, operatorToken} = property
2585 key = if property instanceof Assign and context is 'object'
2593 key.error 'invalid object key' unless context isnt 'object' and key.this
2604 @expandProperty(property) for property in @properties
2610 for property in @properties
2611 if property instanceof Assign and property.context is 'object'
2638 property.ast(o) for property in @expandProperties()
2644 {variable: @key, value, context} = fromAssign
2645 if context is 'object'
2686 return yes for obj in @objects when obj instanceof Elision
2693 for obj, i in @objects
2710 for obj, objIndex in @objects
2718 compiledObjs = (obj.compileToFragments o, LEVEL_LIST for obj in @objects)
2728 for fragments, index in compiledObjs
2729 for fragment in fragments
2741 for fragment, fragmentIndex in answer
2749 for fragment in answer when fragment.isHereComment
2756 for obj in @objects when obj.assigns name then return yes
2760 for obj in @objects
2769 for object in @objects
2786 object.ast(o, LEVEL_LIST) for object in @objects
2856 # Figure out the appropriate name for this class
2881 for expression in expressions.slice()
2906 for method in initializer when method instanceof Code
2911 method.context = @name
2917 @body.expressions = (expression.hoist() for expression in initializer)
2922 # This is the key method for determining whether an expression in a class
2925 # or identical) node for inclusion in the class initializer, otherwise
2932 # initializer as an escape hatch for ES features that are not implemented
2950 return yes if node.context is 'object' and not node.variable.hasProperties()
2993 node.context is 'object' and not node.variable.hasProperties()
3018 @ctor.thisAssignments = for method in @boundMethods
3128 for node, i in child.expressions
3144 node.context = @name
3146 # Make class/prototype assignments for invalid ES properties
3148 result = for assign in assigns
3152 delete assign.context
3278 # The AST for `ImportClause` is the non-nested list of import specifiers
3351 compiledList = (specifier.compileToFragments o, LEVEL_LIST for specifier in @specifiers)
3355 for fragments, index in compiledList
3364 specifier.ast(o) for specifier in @specifiers
3462 constructor: (@variable, @value, @context, options = {}) ->
3464 {@param, @subpattern, @operatorToken, @moduleDeclaration, @originalContext = @context} = options
3472 o?.level is LEVEL_TOP and @context? and (@moduleDeclaration or "?" in @context)
3479 @[if @context is 'object' then 'value' else 'variable'].assigns name
3493 return unless not @context or @context is '**='
3526 # other herecomments are already staged there) for compatibility
3527 # with Flow typing. Don’t do this if this assignment is for a
3541 # we've been assigned to, for correct internal references. If the variable
3559 return @compileSpecialMath o if @context in ['//=', '%%=']
3572 if @context is 'object'
3578 answer = compiledName.concat @makeCode(" #{ @context or '=' } "), val
3609 # Special-case for `{} = a` and `[] = a` (empty patterns).
3636 # `{a, b} = fn()` must be cached, for example. Make vvar into a simple
3659 (i for obj, i in objs when obj instanceof Assign and obj.context is 'object')
3663 return yes for obj in objs when not obj.isAssignable()
3674 for obj, i in objs
3678 if obj instanceof Assign and obj.context is 'object'
3746 # Disallow `[...] = a` for some reason. (Could be equivalent to `[] = a`?)
3762 splats = (i for obj, i in objects when obj instanceof Splat)
3764 expans = (i for obj, i in objects when obj instanceof Expansion)
3781 if "?" in @context
3785 fragments = new Op(@context[...-1], left, new Assign(right, @value, '=')).compileToFragments o
3792 new Assign(left, new Op(@context[...-1], right, @value)).compileToFragments o
3833 …@variable.error "the variable \"#{name}\" can't be assigned with #{@context} because it has not be…
3836 @context in ['||=', '&&=', '?=']
3875 # When for the purposes of walking the contents of a function body, the Code
3916 @context = o.scope.method.context if o.scope.method?.bound
3917 @context = 'this' unless @context
3953 # body for any reason, for example it’s destructured with `this`, also
3956 for param, i in @params
4022 # isn’t kept for eventual output, don’t include comments in this
4046 …new Arr [new Splat(new IdentifierLiteral(splatParamName)), (param.asReference o for param in param…
4080 for param, i in params
4094 comment.unshift = no for comment in @funcGlyph.comments
4107 answer = @joinFragmentArrays (@makeCode m for m in modifiers), ' '
4133 param.eachName iterator for param in @params
4140 # Short-circuit `replaceInContext` method to prevent it from crossing context boundaries. Bound
4141 # functions have the same context.
4173 for param in @params
4196 # Find all super calls in the given context node;
4198 eachSuperCall: (context, iterator, {checkForThisBeforeSuper = yes} = {}) ->
4201 context.traverseChildren yes, (child) =>
4222 for param in @params
4291 params: @paramForAst(param).ast(o) for param in @params
4296 # matches the Babel AST for anonymous function expressions/arrow functions
4314 # these parameters can also attach themselves to the context of the function,
4374 for obj in name.objects ? []
4378 if obj instanceof Assign and not obj.context?
4409 # Rename a param by replacing the given AST node for a name with a new node.
4410 # This needs to ensure that the the source for object destructuring does not change.
4417 … # No need to assign a new variable for the destructured variable if the variable isn't reserved.
4508 # Array elision element (for example, [,a, , , b, , c, ,]).
4558 for node in expressions
4706 for param in func.params or []
4855 operands: (operand.ast(o, LEVEL_OP) for operand in operands)
4898 for obj in @array.base.objects when obj instanceof Splat
4909 for item, i in @array.base.objects
5063 # Checks a variable for existence -- not `null` and not `undefined`. This is
5073 for comment in child.comments
5091 # so that an existence check roughly corresponds to a check for truthiness.
5092 # Do *not* change this to `===` for `null`, as this will break mountains of
5094 # use `===` because this use case is for parity with ES2015+ default values,
5186 for comment in salvagedComments
5207 for comment in node.comments
5230 for element in elements
5265 for element, index in elements
5312 # CoffeeScript's replacement for the *for* loop is our array and object
5313 # comprehensions, that compile into *for* loops here. They also act as an
5339 @[attr] = source[attr] ? @[attr] for attr in attribs
5341 @index.error 'cannot use index with for-from' if @from and @index
5342 … @ownTag.error "cannot use own with for-#{if @from then 'from' else 'in'}" if @own and not @object
5345 @awaitTag.error 'await must be used with for-from' if @await and not @from
5352 # Move up any comments in the “`for` line”, i.e. the line of code with `for`,
5353 # from any child nodes of that line up to the `for` node itself so that these
5354 # comments get output, and get output above the `for` loop.
5355 for attribute in ['source', 'guard', 'step', 'name', 'index'] when @[attribute]
5360 # we’re done compiling this `for` loop; so just shift them up to
5361 # output above the `for` line.
5362 comment.newLine = comment.unshift = yes for comment in node.comments
5368 # loop, filtering, stepping, and result saving for array, object, and range
5454 forCode = if @await then 'for ' else 'for ('
5501 for {block} in @cases
5506 block.makeReturn(results, mark) for {block} in @cases
5517 for {conditions, block}, i in @cases
5518 for cond in flatten [conditions]
5536 for kase, caseIndex in @cases
5540 for test, testIndex in tests
5557 kase.ast(o) for kase in cases
5721 expression.ast(o) for expression in @expressions
5737 # Shortcuts to speed up the lookup time for native functions.
5743 # Levels indicate a node's position in the AST. Useful for knowing if
5752 # Tabs are two spaces for pretty printing.
5772 # Helper for ensuring that utility functions are assigned at the top level.
5790 # indent a line of code, now we must account for the possibility of comments
5794 for fragment, fragmentIndex in fragments
5804 for comment in node.comments
5820 for fragment, fragmentIndex in fragments when not fragment.isComment
5923 # Helpers for `mergeLocationData` and `mergeAstLocationData` below.
6107 # last_line/last_column aren’t used for AST generation anyway.