Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
}
exports.XJSIdentifier = function (node) {
if (esutils.keyword.isIdentifierName(node.name)) {
node.type = "Identifier";
} else {
return t.literal(node.name);
}
};
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
}
export function isValidIdentifier(name: string): boolean {
if (typeof name !== "string" || esutils.keyword.isReservedWordES6(name, true)) {
return false;
} else {
return esutils.keyword.isIdentifierNameES6(name);
}
}
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));
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`)
}
function isIdentifier(name, ecmaVersion) {
if (ecmaVersion >= 6) {
return esutils.keyword.isIdentifierES6(name);
}
return esutils.keyword.isIdentifierES5(name);
}
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));
}
}, {
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));
}
}, {
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;
}
};