How to use the arrayExpression function from babel-types

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

25
26
27
28
29
30
31
32
33
34
const vars = freeVariablesInMessage(node);
const message = extractElementMessageWithoutSideEffects(node);
const fallback = this.makeFallback(node);
const transformed = transformElementMarker({
    MESSAGE: types.stringLiteral(message),
    ARGS: types.arrayExpression(
        vars.map(v => types.identifier(v))
    ),
    FALLBACK: fallback,
});
fork icon6
star icon21
watch icon3

+ 3 other calls in file

73
74
75
76
77
78
79
80
81
82
// :foo -> 'foo'
case l.KeywordNode:
  return t.stringLiteral(resolveKeyword(node.name));
// [1 2 3] -> [1, 2, 3]
case l.VectorNode:
  return t.arrayExpression(node.values.map(translate));
// {:foo 1, :bar 2} -> new Map([['foo', 1], ['bar', 2]])
case l.MapNode: {
  invariant(
    isEven(node.values.length),
fork icon1
star icon10
watch icon2

+ 29 other calls in file

39
40
41
42
43
44
45
46
47
48

const NullableTypeAnnotation = (node, initialPath) =>
  t.objectExpression([
    t.objectProperty(
      t.identifier('anyOf'),
      t.arrayExpression([
        NullLiteralTypeAnnotation(),
        convert(node.typeAnnotation, initialPath)
      ])
    )
fork icon1
star icon9
watch icon2

+ 92 other calls in file

12
13
14
15
16
17
18
19
20
21
} else if (typeof obj === 'string') {
  return t.stringLiteral(obj);
} else if (typeof obj === 'boolean') {
  return t.booleanLiteral(obj);
} else if (Array.isArray(obj)) {
  return t.arrayExpression(obj.map(objToAst));
} else if (typeof obj === 'object') {
  const properties = Object.getOwnPropertyNames(obj).map(prop => {
    return t.objectProperty(t.stringLiteral(prop), objToAst(obj[prop]));
  });
fork icon1
star icon5
watch icon2

+ 3 other calls in file

131
132
133
134
135
136
137
138
139
    }
    last = current
    current = current.parentPath
  }

  rightExpression = t.arrayExpression([rightExpression, t.stringLiteral(firstKey)])
  // 构造赋值语句并挂到要改的path下,等对memberExpression访问exit时处理
  last.assignment = t.assignmentExpression('=', t.memberExpression(t.identifier('renderData'), t.stringLiteral(keyPath.toString()), true), rightExpression)
}
fork icon349
star icon0
watch icon3

118
119
120
121
122
123
124
125
126
127

  return t.callExpression(c.HELPER, [
    c.CONTEXT,
    c.HELPERS,
    t.stringLiteral(branch.helperName),
    t.arrayExpression(compile(branch.args)),
  ]);
},
OpenIf(branch, nextBranch) {
  let test = transforms[branch.test.tokenType](branch.test);
fork icon17
star icon0
watch icon5

58
59
60
61
62
63
64
65
66
67
  return arrayTypeAssertTemplate(valueAssertion);
};

const unionNodeTypeAssertTemplate = names =>
  tea.callExpression(tea.identifier('assertOneOf'), [
    tea.arrayExpression(names.map(name => tea.stringLiteral(name)))
  ]);

const valueOfUnionNodeType = valueNode => {
  if (
fork icon5
star icon0
watch icon2

+ 23 other calls in file

15
16
17
18
19
20
21
22
23
24
    [ R.is(Object), buildObjectLiteral ],
    [ R.T, nullary(types.nullLiteral) ]
]);

function buildArrayLiteral(arr) {
    return types.arrayExpression(R.map(buildLiteral, arr));
}

// Please note that we only support simple non-circular javascript constructs
function buildObjectLiteral(obj) {
fork icon4
star icon0
watch icon6

+ 9 other calls in file

32
33
34
35
36
37
38
39
40
41
  false,
  false
),
t.objectProperty(
  t.identifier('types'),
  t.arrayExpression([...types.map(type => t.identifier(type))])
),
t.objectMethod(
  'method',
  t.identifier('resolveType'),
fork icon0
star icon3
watch icon2

+ 5 other calls in file

199
200
201
202
203
204
205
206
207
208
  }
})
if (defaultSpecifier) {
  let objArr = [t.nullLiteral()]
  if (Array.isArray(obj)) {
    objArr = t.arrayExpression(astConvert.array(obj))
  } else {
    objArr = t.objectExpression(astConvert.obj(obj))
  }
  astPath.replaceWith(t.variableDeclaration('const', [t.variableDeclarator(t.identifier(defaultSpecifier), objArr)]))
fork icon0
star icon4
watch icon5

+ 3 other calls in file

131
132
133
134
135
136
137
138
139
140
if (result[rulesBuffer[name].index].expression.right.type === 'ArrayExpression') {
  result[rulesBuffer[name].index].expression.right.elements.push(
    t.identifier(current.expression.right.name)
  );
} else {
  result[rulesBuffer[name].index].expression.right = t.arrayExpression([
    t.identifier(rulesBuffer[name].rule.expression.right.name),
    t.identifier(current.expression.right.name)
  ]);
}
fork icon47
star icon0
watch icon36

14
15
16
17
18
19
20
21
22
23
	classNameValue = classNameAttr.value.expression;
} else if (classNameAttr && t.isStringLiteral(classNameAttr.value)) {
	classNameValue = classNameAttr.value;
}

let classNameArr = classNameValue ? t.arrayExpression([
	classNameValue
]) : t.arrayExpression([]);

let classObjEntries = t.callExpression(
fork icon0
star icon4
watch icon0

97
98
99
100
101
102
103
104
105
106
        val = type === 'number' ? t.numericLiteral(Number(v)) : type === 'string' ? t.stringLiteral(v) : t.booleanLiteral(v);
    } else {
        continue;
    }
} else if (obj.type === 'array') {
    val = t.arrayExpression(obj.value.elements);
} else if (obj.type === 'object') {
    val = t.objectExpression(obj.value.properties);
} else {
    switch (obj.type) {
fork icon0
star icon0
watch icon0

90
91
92
93
94
95
96
97
98
99
  ])
}

const buildRouterStarter = ({ pages, packageName }) => {
  const importers = pages.map(buildRouterImporter)
  const initArrNode = t.arrayExpression(importers)

  return t.expressionStatement(
    t.callExpression(
      t.memberExpression(
fork icon0
star icon0
watch icon1

+ 3 other calls in file

19
20
21
22
23
24
25
26
27
28
const generateLiteral = value => {
  if (_.isString(value)) return t.stringLiteral(value);
  if (_.isBoolean(value)) return t.booleanLiteral(value);
  if (_.isNumber(value)) return t.numericLiteral(value);
  if (_.isNull(value)) return t.nullLiteral();
  if (_.isArray(value)) return t.arrayExpression(value.map(generateLiteral));
  if (_.isObject(value)) {
    const properties = Object.keys(value).map(key =>
      t.objectProperty(t.identifier(key), generateLiteral(value[key]))
    );
fork icon0
star icon0
watch icon4

+ 15 other calls in file

78
79
80
81
82
83
84
85
86
87
    ...Object.entries(
      description.belongsToMany,
    ).map(([attribute, options]) => {
      return t.objectProperty(
        t.stringLiteral(attribute),
        t.arrayExpression([modelVar(options.target_name)]),
      );
    }),
  ]),
],
fork icon0
star icon0
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)