babel

ast

Node {
  type: 'File',
  start: 0,
  end: 1181,
  loc: SourceLocation {
    start: Position { line: 1, column: 0 },
    end: Position { line: 55, column: 22 },
    filename: undefined,
    identifierName: undefined
  },
  range: undefined,
  leadingComments: undefined,
  trailingComments: undefined,
  innerComments: undefined,
  extra: undefined,
  errors: [],
  program: Node {
    type: 'Program',
    start: 0,
    end: 1181,
    loc: SourceLocation {
      start: [Position],
      end: [Position],
      filename: undefined,
      identifierName: undefined
    },
    range: undefined,
    leadingComments: undefined,
    trailingComments: undefined,
    innerComments: undefined,
    extra: undefined,
    sourceType: 'module',
    interpreter: null,
    body: [
      [Node], [Node],
      [Node], [Node],
      [Node], [Node],
      [Node], [Node],
      [Node], [Node],
      [Node], [Node]
    ],
    directives: []
  },
  comments: [
    {
      type: 'CommentLine',
      value: ' 给你一把"螺丝刀"——recast',
      start: 130,
      end: 150,
      loc: [SourceLocation]
    },
    {
      type: 'CommentLine',
      value: ' 你的"机器"——一段代码',
      start: 186,
      end: 201,
      loc: [SourceLocation]
    },
    {
      type: 'CommentLine',
      value: ' 我们使用了很奇怪格式的代码,想测试是否能维持代码结构',
      start: 202,
      end: 231,
      loc: [SourceLocation]
    },
    {
      type: 'CommentLine',
      value: ' 用螺丝刀解析机器',
      start: 342,
      end: 353,
      loc: [SourceLocation]
    },
    {
      type: 'CommentLine',
      value: ' ast可以处理很巨大的代码文件',
      start: 403,
      end: 421,
      loc: [SourceLocation]
    },
    {
      type: 'CommentLine',
      value: ' 但我们现在只需要代码块的第一个body,即add函数',
      start: 422,
      end: 451,
      loc: [SourceLocation]
    },
    {
      type: 'CommentLine',
      value: ' console.log(add)',
      start: 486,
      end: 505,
      loc: [SourceLocation]
    },
    {
      type: 'CommentLine',
      value: ' 引入变量声明,变量符号,函数声明三种“模具”',
      start: 507,
      end: 532,
      loc: [SourceLocation]
    },
    {
      type: 'CommentLine',
      value: ' 将准备好的组件置入模具,并组装回原来的ast对象。',
      start: 626,
      end: 654,
      loc: [SourceLocation]
    },
    {
      type: 'CommentLine',
      value: ' Anonymize the function expression.',
      start: 767,
      end: 804,
      loc: [SourceLocation]
    },
    {
      type: 'CommentLine',
      value: ' console.log(tempTokens)',
      start: 966,
      end: 992,
      loc: [SourceLocation]
    },
    {
      type: 'CommentLine',
      value: ' ast.tokens =tempTokens',
      start: 993,
      end: 1018,
      loc: [SourceLocation]
    },
    {
      type: 'CommentLine',
      value: " console.log('ast->',ast)",
      start: 1019,
      end: 1046,
      loc: [SourceLocation]
    },
    {
      type: 'CommentLine',
      value: '将AST对象重新转回可以阅读的代码',
      start: 1099,
      end: 1118,
      loc: [SourceLocation]
    },
    {
      type: 'CommentLine',
      value: ' console.log(output)',
      start: 1159,
      end: 1181,
      loc: [SourceLocation]
    }
  ]
}

path

path-> <ref *1> NodePath {
  contexts: [
    TraversalContext {
      queue: [Array],
      priorityQueue: [],
      parentPath: [NodePath],
      scope: [Scope],
      state: undefined,
      opts: [Object]
    }
  ],
  state: undefined,
  opts: {
    CallExpression: { enter: [Array] },
    _exploded: true,
    _verified: true
  },
  _traverseFlags: 0,
  skipKeys: null,
  parentPath: NodePath {
    contexts: [ [TraversalContext] ],
    state: undefined,
    opts: { CallExpression: [Object], _exploded: true, _verified: true },
    _traverseFlags: 0,
    skipKeys: null,
    parentPath: NodePath {
      contexts: [Array],
      state: undefined,
      opts: [Object],
      _traverseFlags: 0,
      skipKeys: null,
      parentPath: [NodePath],
      container: [Node],
      listKey: undefined,
      key: 'alternate',
      node: [Node],
      type: 'BlockStatement',
      parent: [Node],
      hub: undefined,
      data: null,
      context: [TraversalContext],
      scope: [Scope]
    },
    container: [ [Node] ],
    listKey: 'body',
    key: 0,
    node: Node {
      type: 'ExpressionStatement',
      start: 90,
      end: 109,
      loc: [SourceLocation],
      range: undefined,
      leadingComments: undefined,
      trailingComments: undefined,
      innerComments: undefined,
      extra: undefined,
      expression: [Node]
    },
    type: 'ExpressionStatement',
    parent: Node {
      type: 'BlockStatement',
      start: 82,
      end: 115,
      loc: [SourceLocation],
      range: undefined,
      leadingComments: undefined,
      trailingComments: undefined,
      innerComments: undefined,
      extra: undefined,
      body: [Array],
      directives: []
    },
    hub: undefined,
    data: null,
    context: TraversalContext {
      queue: [Array],
      priorityQueue: [],
      parentPath: [NodePath],
      scope: [Scope],
      state: undefined,
      opts: [Object]
    },
    scope: Scope {
      uid: 2,
      path: [NodePath],
      block: [Node],
      labels: Map(0) {},
      inited: true,
      bindings: [Object: null prototype] {},
      references: [Object: null prototype] {},
      globals: [Object: null prototype] {},
      uids: [Object: null prototype] {},
      data: [Object: null prototype] {},
      crawling: undefined
    }
  },
  container: Node {
    type: 'ExpressionStatement',
    start: 90,
    end: 109,
    loc: SourceLocation {
      start: [Position],
      end: [Position],
      filename: undefined,
      identifierName: undefined
    },
    range: undefined,
    leadingComments: undefined,
    trailingComments: undefined,
    innerComments: undefined,
    extra: undefined,
    expression: Node {
      type: 'CallExpression',
      start: 90,
      end: 109,
      loc: [SourceLocation],
      range: undefined,
      leadingComments: undefined,
      trailingComments: undefined,
      innerComments: undefined,
      extra: undefined,
      callee: [Node],
      arguments: [Array]
    }
  },
  listKey: undefined,
  key: 'expression',
  node: Node {
    type: 'CallExpression',
    start: 90,
    end: 109,
    loc: SourceLocation {
      start: [Position],
      end: [Position],
      filename: undefined,
      identifierName: undefined
    },
    range: undefined,
    leadingComments: undefined,
    trailingComments: undefined,
    innerComments: undefined,
    extra: undefined,
    callee: Node {
      type: 'MemberExpression',
      start: 90,
      end: 100,
      loc: [SourceLocation],
      range: undefined,
      leadingComments: undefined,
      trailingComments: undefined,
      innerComments: undefined,
      extra: undefined,
      object: [Node],
      computed: false,
      property: [Node]
    },
    arguments: [ [Node], [Node] ]
  },
  type: 'CallExpression',
  parent: Node {
    type: 'ExpressionStatement',
    start: 90,
    end: 109,
    loc: SourceLocation {
      start: [Position],
      end: [Position],
      filename: undefined,
      identifierName: undefined
    },
    range: undefined,
    leadingComments: undefined,
    trailingComments: undefined,
    innerComments: undefined,
    extra: undefined,
    expression: Node {
      type: 'CallExpression',
      start: 90,
      end: 109,
      loc: [SourceLocation],
      range: undefined,
      leadingComments: undefined,
      trailingComments: undefined,
      innerComments: undefined,
      extra: undefined,
      callee: [Node],
      arguments: [Array]
    }
  },
  hub: undefined,
  data: null,
  context: TraversalContext {
    queue: [ [Circular *1] ],
    priorityQueue: [],
    parentPath: NodePath {
      contexts: [Array],
      state: undefined,
      opts: [Object],
      _traverseFlags: 0,
      skipKeys: null,
      parentPath: [NodePath],
      container: [Array],
      listKey: 'body',
      key: 0,
      node: [Node],
      type: 'ExpressionStatement',
      parent: [Node],
      hub: undefined,
      data: null,
      context: [TraversalContext],
      scope: [Scope]
    },
    scope: Scope {
      uid: 2,
      path: [NodePath],
      block: [Node],
      labels: Map(0) {},
      inited: true,
      bindings: [Object: null prototype] {},
      references: [Object: null prototype] {},
      globals: [Object: null prototype] {},
      uids: [Object: null prototype] {},
      data: [Object: null prototype] {},
      crawling: undefined
    },
    state: undefined,
    opts: { CallExpression: [Object], _exploded: true, _verified: true }
  },
  scope: <ref *2> Scope {
    uid: 2,
    path: NodePath {
      contexts: [Array],
      state: undefined,
      opts: [Object],
      _traverseFlags: 0,
      skipKeys: null,
      parentPath: [NodePath],
      container: [Node],
      listKey: undefined,
      key: 'alternate',
      node: [Node],
      type: 'BlockStatement',
      parent: [Node],
      hub: undefined,
      data: null,
      context: [TraversalContext],
      scope: [Circular *2]
    },
    block: Node {
      type: 'BlockStatement',
      start: 82,
      end: 115,
      loc: [SourceLocation],
      range: undefined,
      leadingComments: undefined,
      trailingComments: undefined,
      innerComments: undefined,
      extra: undefined,
      body: [Array],
      directives: []
    },
    labels: Map(0) {},
    inited: true,
    bindings: [Object: null prototype] {},
    references: [Object: null prototype] {},
    globals: [Object: null prototype] {},
    uids: [Object: null prototype] {},
    data: [Object: null prototype] {},
    crawling: undefined
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值