Sha256: 4037c925ea10817018996812e1b38e9e1344636b1fdf066aeae8fb13e24f4e04

Contents?: true

Size: 1.61 KB

Versions: 12

Compression:

Stored size: 1.61 KB

Contents

import {Parser} from "./state"
import {SourceLocation} from "./location"

// Start an AST node, attaching a start offset.

const pp = Parser.prototype

export class Node {}

pp.startNode = function() {
  let node = new Node
  node.start = this.start
  if (this.options.locations)
    node.loc = new SourceLocation(this, this.startLoc)
  if (this.options.directSourceFile)
    node.sourceFile = this.options.directSourceFile
  if (this.options.ranges)
    node.range = [this.start, 0]
  return node
}

pp.startNodeAt = function(pos, loc) {
  let node = new Node
  if (Array.isArray(pos)){
    if (this.options.locations && loc === undefined) {
      // flatten pos
      loc = pos[1]
      pos = pos[0]
    }
  }
  node.start = pos
  if (this.options.locations)
    node.loc = new SourceLocation(this, loc)
  if (this.options.directSourceFile)
    node.sourceFile = this.options.directSourceFile
  if (this.options.ranges)
    node.range = [pos, 0]
  return node
}

// Finish an AST node, adding `type` and `end` properties.

pp.finishNode = function(node, type) {
  node.type = type
  node.end = this.lastTokEnd
  if (this.options.locations)
    node.loc.end = this.lastTokEndLoc
  if (this.options.ranges)
    node.range[1] = this.lastTokEnd
  return node
}

// Finish node at given position

pp.finishNodeAt = function(node, type, pos, loc) {
  node.type = type
  if (Array.isArray(pos)){
    if (this.options.locations && loc === undefined) {
      // flatten pos
      loc = pos[1]
      pos = pos[0]
    }
  }
  node.end = pos
  if (this.options.locations)
    node.loc.end = loc
  if (this.options.ranges)
    node.range[1] = pos
  return node
}

Version data entries

12 entries across 12 versions & 4 rubygems

Version Path
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/acorn/src/node.js
minimum_viable_product-0.0.11 test/dummy/node_modules/acorn/src/node.js
brwy_rails-0.0.6 test/dummy/node_modules/acorn/src/node.js
brwy_rails-0.0.5 test/dummy/node_modules/acorn/src/node.js
xcodebuild-helper-1.2.3 externals/ios-sim-master/node_modules/acorn/src/node.js
brwy_rails-0.0.4 test/dummy/node_modules/acorn/src/node.js
brwy_rails-0.0.3 test/dummy/node_modules/acorn/src/node.js
brwy_rails-0.0.2 test/dummy/node_modules/acorn/src/node.js
brwy_rails-0.0.1 test/dummy/node_modules/acorn/src/node.js
gulp_assets-1.0.0.pre.5 template/node_modules/babel-core/node_modules/acorn-jsx/node_modules/acorn/src/node.js
gulp_assets-1.0.0.pre.4 template/node_modules/babel-core/node_modules/acorn-jsx/node_modules/acorn/src/node.js
gulp_assets-1.0.0.pre.3 template/node_modules/babel-core/node_modules/acorn-jsx/node_modules/acorn/src/node.js