How to use the esutils.keyword function in esutils

To help you get started, we’ve selected a few esutils 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 / babel-plugin-transform-jsx-to-html / src / index.js View on Github external
const value = convertAttributeValue(node.value || t.booleanLiteral(true));

  if (t.isStringLiteral(value) && !t.isJSXExpressionContainer(node.value)) {
    value.value = value.value.replace(/\n\s+/g, ' ');

    // "raw" JSXText should not be used from a StringLiteral because it needs to be escaped.
    if (value.extra && value.extra.raw) {
      delete value.extra.raw;
    }
  }

  if (t.isJSXNamespacedName(node.name)) {
    node.name = t.stringLiteral(
      node.name.namespace.name + ':' + node.name.name.name,
    );
  } else if (esutils.keyword.isIdentifierNameES6(node.name.name)) {
    node.name.type = 'Identifier';
  } else {
    node.name = t.stringLiteral(node.name.name);
  }

  return t.inherits(t.objectProperty(node.name, value), node);
}
github babel / babel / lib / 6to5 / transformation / transformers / jsx.js View on Github external
exports.XJSIdentifier = function (node) {
  if (esutils.keyword.isIdentifierName(node.name)) {
    node.type = "Identifier";
  } else {
    return t.literal(node.name);
  }
};
github sx1989827 / DOClever / Client / node_modules / babel-plugin-transform-vue-jsx / index.js View on Github external
function convertJSXIdentifier (node, parent) {
    if (t.isJSXIdentifier(node)) {
      if (node.name === 'this' && t.isReferenced(node, parent)) {
        return t.thisExpression()
      } else if (esutils.keyword.isIdentifierNameES6(node.name)) {
        node.type = 'Identifier'
      } else {
        return t.stringLiteral(node.name)
      }
    } else if (t.isJSXMemberExpression(node)) {
      return t.memberExpression(
        convertJSXIdentifier(node.object, node),
        convertJSXIdentifier(node.property, node)
      )
    }
    return node
  }
github forivall / tacoscript / src / validators.js View on Github external
export function isValidIdentifier(name: string): boolean {
  if (typeof name !== "string" || esutils.keyword.isReservedWordES6(name, true)) {
    return false;
  } else {
    return esutils.keyword.isIdentifierNameES6(name);
  }
}
github estools / esvalid / index.js View on Github external
strict = state.strict || any(function(d) { return d === "use strict"; }, directives(node.body.body));
            if (strict && !state.strict)
              recursionFn = errorsP(merge({}, state, {strict: true, inFunc: true}));
            [].push.apply(errors, recursionFn({type: "Program", body: node.body.body}));
          } else {
            [].push.apply(errors, recursionFn(node.body));
          }
        }
        break;

      case "Identifier":
        if (node.name == null)
          errors.push(new E(node, "Identifier `name` member must be non-null"));
        else if (!esutils.keyword.isIdentifierName(node.name))
          errors.push(new E(node, "Identifier `name` member must be a valid IdentifierName"));
        else if (esutils.keyword.isReservedWordES5(node.name, state.strict))
          errors.push(new E(node, "Identifier `name` member must not be a ReservedWord"));
        break;

      case "IfStatement":
        if (!isExpression(node.test))
          errors.push(new E(node, "IfStatement `test` member must be an expression node"));
        if (!isStatement(node.consequent))
          errors.push(new E(node, "IfStatement `consequent` member must be a statement node"));
        if (node.alternate != null && !isStatement(node.alternate))
          errors.push(new E(node, "IfStatement `alternate` member must be a statement node or null"));
        if (node.alternate != null && node.consequent != null && esutils.ast.isProblematicIfStatement(node))
          errors.push(new E(node, "IfStatement with null `alternate` must not be the `consequent` of an IfStatement with a non-null `alternate`"));
        if (node.test != null)
          [].push.apply(errors, recurse(node.test));
        if (node.consequent != null)
          [].push.apply(errors, recurse(node.consequent));
github calebmer / node_modules / babel-plugin-transform-jsx / src / index.js View on Github external
nodes.forEach(node => {
        switch (node.type) {
          case 'JSXAttribute': {
            if (!object) {
              object = []
            }

            const attributeName = JSXAttributeName(node.name)
            const objectKey = esutils.keyword.isIdentifierNameES6(attributeName.value) ? t.identifier(attributeName.value) : attributeName

            object.push(t.objectProperty(objectKey, JSXAttributeValue(node.value)))
            break
          }
          case 'JSXSpreadAttribute': {
            if (object) {
              objects.push(t.objectExpression(object))
              object = null
            }

            objects.push(node.argument)
            break
          }
          default:
            throw new Error(`${node.type} cannot be used as a JSX attribute`)
        }
github graalvm / graaljs / tools / node_modules / eslint / lib / rules / func-name-matching.js View on Github external
function isIdentifier(name, ecmaVersion) {
    if (ecmaVersion >= 6) {
        return esutils.keyword.isIdentifierES6(name);
    }
    return esutils.keyword.isIdentifierES5(name);
}
github shapesecurity / shift-codegen-js / dist / index.js View on Github external
value: function reduceStaticPropertyName(node) {
      var n;
      if (_esutils.keyword.isIdentifierNameES6(node.value)) {
        return t(node.value);
      } else if ((n = parseFloat(node.value), n === n)) {
        return new NumberCodeRep(n);
      }
      return t(escapeStringLiteral(node.value));
    }
  }, {
github habitlab / habitlab / src / jspm_packages / npm / shift-codegen@4.0.3 / dist / minimal-codegen.js View on Github external
value: function reduceStaticPropertyName(node) {
      var n;
      if (_esutils.keyword.isIdentifierNameES6(node.value)) {
        return t(node.value);
      } else if (n = parseFloat(node.value), n === n) {
        return new _coderep.NumberCodeRep(n);
      }
      return t((0, _coderep.escapeStringLiteral)(node.value));
    }
  }, {
github babel / babel / lib / 6to5 / transformation / transformers / _member-expression-keywords.js View on Github external
exports.MemberExpression = function (node) {
  var prop = node.property;
  if (t.isIdentifier(prop) && esutils.keyword.isKeywordES6(prop.name, true)) {
    node.property = t.literal(prop.name);
    node.computed = true;
  }
};