How to use the babel-types.numericLiteral function in babel-types

To help you get started, we’ve selected a few babel-types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alibaba / rax / packages / mp-loader / src / transpiler / expression.js View on Github external
}
        if (!members.length) {
          return;
        }
        members.forEach(function(m) {
          // x[y]
          if (m.computed) {
            args.push(m.property);
          } else {
            // x.y
            args.push(t.stringLiteral(m.property.name));
          }
        });
        let callArgs = [t.arrayExpression(args)];
        if (parent.callee === node) {
          callArgs.push(t.numericLiteral(1));
        }
        let newNode = t.callExpression(t.identifier(memberFn), callArgs);
        newNode.callee.__rmlSkipped = 1;
        // will process a.v of x.y[a.v]
        path.replaceWith(newNode);
        // path.skip();
      }
    }
  };
github ifgyong / demo / React-native / Helloword / node_modules / babel-plugin-transform-regenerator / node_modules / regenerator-transform / src / emit.js View on Github external
t.switchCase(this.finalLoc, [
            // Intentionally fall through to the "end" case...
        ]),

        // So that the runtime can jump to the final location without having
        // to know its offset, we provide the "end" case as a synonym.
        t.switchCase(t.stringLiteral("end"), [
            // This will check/clear both context.thrown and context.rval.
            t.returnStatement(
                t.callExpression(this.contextProperty("stop"), [])
            )
        ])
    );

    return t.whileStatement(
        t.numericLiteral(1),
        t.switchStatement(
            t.assignmentExpression(
                "=",
                this.contextProperty("prev"),
                this.contextProperty("next")
            ),
            cases
        )
    );
};
github sx1989827 / DOClever / SBDocClient / node_modules / regenerator-transform / src / emit.js View on Github external
t.switchCase(this.finalLoc, [
      // Intentionally fall through to the "end" case...
    ]),

    // So that the runtime can jump to the final location without having
    // to know its offset, we provide the "end" case as a synonym.
    t.switchCase(t.stringLiteral("end"), [
      // This will check/clear both context.thrown and context.rval.
      t.returnStatement(
        t.callExpression(this.contextProperty("stop"), [])
      )
    ])
  );

  return t.whileStatement(
    t.numericLiteral(1),
    t.switchStatement(
      t.assignmentExpression(
        "=",
        this.contextProperty("prev"),
        this.contextProperty("next")
      ),
      cases
    )
  );
};
github interlockjs / interlock / src / util / ast.js View on Github external
function fromVal (val) {
  if (isArray(val)) {
    return fromArray(val); // eslint-disable-line no-use-before-define
  } else if (isObject(val)) {
    return fromObject(val); // eslint-disable-line no-use-before-define
  } else if (isFunction(val)) {
    return fromFunction(val); // eslint-disable-line no-use-before-define
  } else if (isNumber(val)) {
    return t.numericLiteral(val);
  } else if (isString(val)) {
    return t.stringLiteral(val);
  }
  throw new Error("Cannot transform value into AST.", val);
}
github trivago / melody / packages / melody-extension-core / src / visitors / tests.js View on Github external
exit(path) {
                const expr = t.unaryExpression(
                    '!',
                    t.unaryExpression(
                        '!',
                        t.binaryExpression(
                            '%',
                            path.get('expression').node,
                            t.numericLiteral(2)
                        )
                    )
                );
                expr.extra = { parenthesizedArgument: true };
                path.replaceWithJS(expr);
            },
        },
github Gregoor / syntactor / src / components / editor.js View on Github external
selectedInput.selectionStart + (direction === 'LEFT' ? -1 : 1),
          0,
          selectedInput.value.length
        ))
    ) {
      event.preventDefault();
      return this.changeSelected((ast, selected) => ({
        direction,
        selected: navigate(direction, ast, selected)
      }));
    }

    const enteredNumber = parseInt(event.key, 10);
    if (isNullLiteral(selectedNode) && !isNaN(enteredNumber)) {
      event.preventDefault();
      return this.replace(numericLiteral(enteredNumber));
    }

    function findActionFor(keyMappings: KeyMapping[], event: any) {
      for (const { mappings, name, keys, modifiers, test, type } of keyMappings) {
        if (
          (modifiers &&
            (Array.isArray(modifiers)
              ? modifiers
              : modifiers(selectedNode, selected)
            ).some(modifier => !event[modifier + 'Key'])) ||
          (keys && keys.every(key => key !== event.key)) ||
          (test && !test(selectedNode, selected))
        ) {
          continue;
        }
github plasma-umass / Stopify / src / cpsVisitor.ts View on Github external
ExpressionStatement: function (path) {
        if (isCPS(path.node)) return;
        if (t.isFunctionExpression(path.node.expression)) return;

        path.node.cps = true;
        const k = path.scope.generateUidIdentifier('k');
        const kCall = t.callExpression(k, [t.unaryExpression('void', t.numericLiteral(0))]);
        kCall.cps = true;
        const kReturn = t.returnStatement(kCall);
        kReturn.cps = true;
        const kBody = t.blockStatement([path.node, kReturn]);
        kBody.cps = true;
        const expFunction = t.functionExpression(null, [k], kBody);
        expFunction.cps = true;
        const newExp = t.expressionStatement(expFunction);
        newExp.cps = true;

        path.replaceWith(newExp);
    },
github parcel-bundler / parcel / src / scope-hoisting / hoist.js View on Github external
MemberExpression(path, asset) {
    if (path.scope.hasBinding('module') || path.scope.getData('shouldWrap')) {
      return;
    }

    if (matchesPattern(path.node, 'module.exports')) {
      path.replaceWith(getExportsIdentifier(asset));
      asset.cacheData.isCommonJS = true;
    }

    if (matchesPattern(path.node, 'module.id')) {
      path.replaceWith(t.numericLiteral(asset.id));
    }

    if (matchesPattern(path.node, 'module.hot')) {
      path.replaceWith(t.identifier('null'));
    }

    if (matchesPattern(path.node, 'module.bundle')) {
      path.replaceWith(t.identifier('require'));
    }
  },