How to use the isStringLiteral function from babel-types

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

43
44
45
46
47
48
49
50
51
52
function isRequire(node, filename) {
  if (
    t.isCallExpression(node) &&
    t.isIdentifier(node.callee, { name: 'require' }) &&
    node.arguments.length === 1 &&
    t.isStringLiteral(node.arguments[0])
  ) {
    var relative = node.arguments[0].value;
    var fullPath = resolve.sync(relative, { basedir: dirname(filename) });
    return { relative: relative, fullPath: fullPath };
fork icon59
star icon89
watch icon10

+ 25 other calls in file

119
120
121
122
123
124
125
126
127
128
enter(path) {
    let callNode = path.parentPath.node;
    let nameNode = callNode.arguments && callNode.arguments[0] ? callNode.arguments[0] : null;

    if (t.isCallExpression(callNode)
        && t.isStringLiteral(nameNode)
        && External_Scheme.test(nameNode.value)
    ) {
        let args = callNode.arguments;
        path.parentPath.replaceWith(
fork icon2
star icon6
watch icon3

+ 11 other calls in file

34
35
36
37
38
39
40
41
42
43

let isRequire =
  types.isIdentifier(callee) &&
  callee.name === 'require' &&
  args.length === 1 &&
  types.isStringLiteral(args[0]);

if (isRequire) {
  addDependency(asset, args[0]);
  return;
fork icon0
star icon3
watch icon3

+ 15 other calls in file

137
138
139
140
141
142
143
144
145
146
  // tabBar
  tabBar = value
  value.properties.forEach(node => {
    if (node.key.name === 'position') tabbarPos = node.value.value
  })
} else if ((key.name === 'iconPath' || key.name === 'selectedIconPath') && t.isStringLiteral(value)) {
  astPath.replaceWith(
    t.objectProperty(t.stringLiteral(key.name), t.callExpression(t.identifier('require'), [t.stringLiteral(`./${value.value}`)]))
  )
}
fork icon0
star icon2
watch icon2

+ 13 other calls in file

61
62
63
64
65
66
67
68
69
70
    }
    break;
case 'BinaryExpression': { // a + b
    if (attrName === 'class' || attrName === 'className') {
        let { left, right } = expr;
        if (t.isStringLiteral(left) || t.isStringLiteral(right)) {
            // 快应用的 bug
            // class={{this.className0 + ' dynamicClassName'}} 快应用会将后者的空格吞掉
            // 影响 class 的求值
            /*  let className =
fork icon330
star icon0
watch icon2

76
77
78
79
80
81
82
83
84
85
            : t.callExpression(PathUtils.addImportOnce(path, 'default', runtimeModule, { nameHint: 'S' }), styleItems.map(s => s.value));

        // We insert the new (computed) style attribute at the end - it's important that it comes at the end because we don't
        // want any spreads to override our computed style attribute. (Technically if there are no spreads, it would be safe to
        // insert it earlier, but we'll just put it at the end for consistency).
        attributes.push(t.jSXAttribute(t.jSXIdentifier('style'), t.isStringLiteral(value) ? value : t.jSXExpressionContainer(value)));
    }
};

/**
fork icon7
star icon0
watch icon0

+ 15 other calls in file

5
6
7
8
9
10
11
12
13
14
  let resolveModule;
  if (t.isStringLiteral(expr))
    resolveModule = expr.value;
  else if (t.isTemplateLiteral(expr))
    resolveModule = expr.quasis[0].value.cooked;
  else if (t.isBinaryExpression(expr) && expr.operator === '+' && t.isStringLiteral(expr.left))
    resolveModule = expr.left.value;
  if (resolveModule && state.resolves.includes(resolveModule) === false)
    state.resolves.push(resolveModule);
}
fork icon2
star icon3
watch icon3

36
37
38
39
40
41
42
43
44
45
},
AssignmentExpression(path) {
    const left = path.node.left;
    if (t.isMemberExpression(left) && (t.isStringLiteral(left.property) || t.isIdentifier(left.property))) {
        const property = left.property;
        const name = t.isStringLiteral(property) ? property.value : property.name;
        path.replaceWith(assignmentExpression({
            OBJECT: left.object,
            PROPERTY: t.stringLiteral(name),
            EXPRESSION: path.node.right
fork icon1
star icon0
watch icon0

+ 7 other calls in file

203
204
205
206
207
208
209
210
211
212
let {callee, arguments: args} = node;
let isRequire =
  babelTypes.isIdentifier(callee) &&
  callee.name === 'require' &&
  args.length === 1 &&
  babelTypes.isStringLiteral(args[0]) &&
  !hasBinding(ancestors, 'require') &&
  !isInFalsyBranch(ancestors);

if (isRequire) {
fork icon0
star icon49
watch icon1

+ 5 other calls in file

30
31
32
33
34
35
36
37
38
39

CallExpression(node, asset, anc) {
    if (node.callee.name === "require" && node.arguments.length === 1 && types.isStringLiteral(node.arguments[0]) && !hasBinding(anc, "require") && !isInFalsyBranch(anc)) {
        deps.push({ value: node.arguments[0].value, type: "RequireCallExpression" })
    }
    else if (node.callee.type === "Import" && node.arguments.length === 1 && types.isStringLiteral(node.arguments[0])) {
        deps.push({ value: node.arguments[0].value, type: "DynamicImportDeclaration" })

        node.callee = template('require("_dynamic_loader")(require)')().expression;
        node.arguments[0] = template('DYNAMIC_MODULE')({DYNAMIC_MODULE: node.arguments[0]}).expression;
fork icon0
star icon2
watch icon0

+ 7 other calls in file

32
33
34
35
36
37
38
39
40
41
    raw: first.value + value.raw,
    cooked: first.value + value.cooked,
  });
  return t.templateLiteral(quasis, second.expressions.slice(0));
}
if (t.isTemplateLiteral(first) && t.isStringLiteral(second)) {
  const quasi = first.quasis[first.quasis.length - 1];
  const value = typeof quasi.value === 'string' ?
    { raw: quasi.value, cooked: quasi.value } : quasi.value;
  const quasis = first.quasis.slice(0);
fork icon0
star icon1
watch icon2

+ 41 other calls in file

81
82
83
84
85
86
87
88
89
90
let {callee, arguments: args} = node;
let isRequire =
  t.isIdentifier(callee) &&
  callee.name === 'require' &&
  args.length === 1 &&
  t.isStringLiteral(args[0]);

if (!isRequire) {
  return false;
}
fork icon0
star icon1
watch icon2

10
11
12
13
14
15
16
17
18
19
});
let classNameValue;

if (classNameAttr && t.isJSXExpressionContainer(classNameAttr.value)) {
	classNameValue = classNameAttr.value.expression;
} else if (classNameAttr && t.isStringLiteral(classNameAttr.value)) {
	classNameValue = classNameAttr.value;
}

let classNameArr = classNameValue ? t.arrayExpression([
fork icon0
star icon4
watch icon0

555
556
557
558
559
560
561
562
563
564
const node = astPath.node;
const callee = node.callee;
const calleeName = astConvert_1.convertAstExpressionToVariable(callee);
const parentPath = astPath.parentPath;
const arg0 = node.arguments[0];
if (calleeName === 'require' && t.isStringLiteral(arg0)) {
    const required = arg0.value;
    if (required === '@tarojs/taro-h5') {
        arg0.value = `@tarojs/taro-h5/dist/index.cjs.js`;
    }
fork icon0
star icon0
watch icon0

+ 23 other calls in file

358
359
360
361
362
363
364
365
366
367
  // tabBar
  tabBar = value
  value.properties.forEach(node => {
    if (node.keyName === 'position') tabbarPos = node.value.value
  })
} else if ((keyName === 'iconPath' || keyName === 'selectedIconPath') && t.isStringLiteral(value)) {
  astPath.replaceWith(
    t.objectProperty(t.stringLiteral(keyName), t.callExpression(t.identifier('require'), [t.stringLiteral(`./${value.value}`)]))
  )
}
fork icon0
star icon0
watch icon0

140
141
142
143
144
145
146
147
148
149
}
var key = property.computed
    ? toConstant(property.key)
    : b.isIdentifier(property.key)
        ? property.key.name
        : b.isStringLiteral(property.key)
            ? property.key.value
            : undefined;
if (!key || key[0] === '_') {
    constant = false;
fork icon0
star icon0
watch icon0

Other functions in babel-types

Sorted by popularity

function icon

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