How to use the file function from babel-types

Find comprehensive JavaScript babel-types.file code examples handpicked from public code repositorys.

66
67
68
69
70
71
72
73
74
75
  return true;
};

function evaluateExpression(node) {
  // Wrap the node in a standalone program so we can traverse it
  node = babelTypes.file(babelTypes.program([babelTypes.expressionStatement(node)]));

  // Find the first expression and evaluate it.
  let res = null;
  traverse(node, {
fork icon0
star icon49
watch icon1

+ 5 other calls in file

27
28
29
30
31
32
33
34
35
36
  Object.assign(new Block, {name: 'root'}),
  Object.assign(new Block, {name: 'end'})
);
const subtraversal = (path) => {
  traverse(
    t.file(
    Object.assign(t.program([
      path.isStatement() ?
        path.node :
        Object.assign(t.expressionStatement(path.node), {loc:path.node.loc})
fork icon5
star icon9
watch icon5

+ 10 other calls in file

83
84
85
86
87
88
89
90
91
92
  } else {
    programBody.push(node)
  }
})

let esFile = t.file(t.program(programBody), ast.comments, ast.tokens)

let output = generate(esFile).code

// writeFileSync(`${distBasePath}${fileTailPath}.ast`, JSON.stringify(ast))
fork icon1
star icon7
watch icon2

+ 6 other calls in file

132
133
134
135
136
137
138
139
140
141
  });
}

function evaluateExpression(node) {
  // Wrap the node in a standalone program so we can traverse it
  node = types.file(types.program([types.expressionStatement(node)]));

  // Find the first expression and evaluate it.
  let res = null;
  traverse(node, {
fork icon0
star icon1
watch icon2

13
14
15
16
17
18
19
20
21
22
}
switch (node.constructor) {
  case l.ProgramNode: {
    const root = translate(node.program);
    const program = Array.isArray(root) ? root : [root];
    return t.file(
      t.program(
        program.map(
          node => (t.isStatement(node) ? node : t.expressionStatement(node))
        ),
fork icon1
star icon10
watch icon2

+ 9 other calls in file

Other functions in babel-types

Sorted by popularity

function icon

babel-types.identifier is the most popular function in babel-types (4076 examples)