How to use the unionTypeAnnotation function from babel-types

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

31
32
33
34
35
36
37
38
39
40
};

function buildType(syntax, key) {
  if (syntax.type === 'Sequence') {
    let types = syntax.terms.map(p => buildType(p, key));
    return t.unionTypeAnnotation(types);
  } else if (syntax.type === 'Keyword') {
    return t.stringLiteral(syntax.name);
  } else if (syntax.type === 'Function') {
    return t.identifier('string');
fork icon10
star icon148
watch icon8

+ 5 other calls in file

87
88
89
90
91
92
93
94
95
96
function unionTypeAnnotation(types: Array<BabelAST>): BabelAST {
  invariant(
    types.length > 0,
    'RelayFlowBabelFactories: cannot create a union of 0 types',
  );
  return types.length === 1 ? types[0] : t.unionTypeAnnotation(types);
}

module.exports = {
  exactObjectTypeAnnotation,
fork icon0
star icon1
watch icon3

+ 5 other calls in file

152
153
154
155
156
157
158
159
160
161

  if (!types.length) {
    return exactObjectTypeAnnotation([]);
  }

  return types.length > 1 ? t.unionTypeAnnotation(types) : types[0];
}

function lineComments(...lines: Array<string>) {
  return lines.map(line => ({type: 'CommentLine', value: ' ' + line}));
fork icon0
star icon1
watch icon2

Other functions in babel-types

Sorted by popularity

function icon

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