Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var prototypeOrStatic = methodNode.static ? '' : '.prototype';
var objectAccessor = state.className + prototypeOrStatic;
if (methodNode.key.type === Syntax.Identifier) {
// foo() {}
methodAccessor = methodNode.key.name;
if (_shouldMungeIdentifier(methodNode.key, state)) {
methodAccessor = _getMungedName(methodAccessor, state);
}
if (isGetter || isSetter) {
methodAccessor = JSON.stringify(methodAccessor);
} else if (reservedWordsHelper.isReservedWord(methodAccessor)) {
methodAccessorComputed = true;
methodAccessor = JSON.stringify(methodAccessor);
}
} else if (methodNode.key.type === Syntax.Literal) {
// 'foo bar'() {} | get 'foo bar'() {} | set 'foo bar'() {}
methodAccessor = JSON.stringify(methodNode.key.value);
methodAccessorComputed = true;
}
if (isSetter || isGetter) {
utils.append(
'Object.defineProperty(' +
objectAccessor + ',' +
methodAccessor + ',' +
'{configurable:true,' +
methodNode.kind + ':function',
state
);
} else {
if (state.g.opts.es3) {
}
utils.append(quoteAttrName(name), state);
utils.append(': ', state);
if (!attr.value) {
state.g.buffer += 'true';
state.g.position = attr.name.range[1];
if (!isLast) {
utils.append(', ', state);
}
} else {
utils.move(attr.name.range[1], state);
// Use catchupNewlines to skip over the '=' in the attribute
utils.catchupNewlines(attr.value.range[0], state);
if (attr.value.type === Syntax.Literal) {
renderJSXLiteral(attr.value, isLast, state);
} else {
renderJSXExpressionContainer(traverse, attr.value, isLast, path, state);
}
}
utils.catchup(attr.range[1], state, trimLeft);
previousWasSpread = false;
});
// appear before the first and after the last element - nothing to add in
// those cases.
if (ii === 0) {
utils.append('"" + ', state);
}
if (ii > 0 && !templateElement.tail) {
// + between substitution and substitution
utils.append(' + ', state);
}
}
utils.move(templateElement.range[1], state);
if (!templateElement.tail) {
var substitution = node.expressions[ii];
if (substitution.type === Syntax.Identifier ||
substitution.type === Syntax.Literal ||
substitution.type === Syntax.MemberExpression ||
substitution.type === Syntax.CallExpression) {
utils.catchup(substitution.range[1], state);
} else {
utils.append('(', state);
traverse(substitution, path, state);
utils.catchup(substitution.range[1], state);
utils.append(')', state);
}
// if next templateElement isn't empty...
if (templateElements[ii + 1].value.cooked !== '') {
utils.append(' + ', state);
}
}
}
utils.move(node.range[1], state);
var objectAccessor = state.className + prototypeOrStatic;
if (methodNode.key.type === Syntax.Identifier) {
// foo() {}
methodAccessor = methodNode.key.name;
if (_shouldMungeIdentifier(methodNode.key, state)) {
methodAccessor = _getMungedName(methodAccessor, state);
}
if (isGetter || isSetter) {
methodAccessor = JSON.stringify(methodAccessor);
} else if (reservedWordsHelper.isReservedWord(methodAccessor)) {
methodAccessor = '[' + JSON.stringify(methodAccessor) + ']';
} else {
methodAccessor = '.' + methodAccessor;
}
} else if (methodNode.key.type === Syntax.Literal) {
// 'foo bar'() {} | get 'foo bar'() {} | set 'foo bar'() {}
methodAccessor = JSON.stringify(methodNode.key.value);
if (!(isGetter || isSetter)) {
methodAccessor = '[' + methodAccessor + ']';
}
}
if (isSetter || isGetter) {
utils.append(
'Object.defineProperty(' +
objectAccessor + ',' +
methodAccessor + ',' +
'{enumerable:true,configurable:true,' +
methodNode.kind + ':function',
state
);
cxName: function(attr) {
if (attr.value.type !== Syntax.Literal) {
throw new Error("cx only accepts a string literal");
} else {
var classNames = attr.value.value.split(/\s+/g);
return 'cx(' + classNames.map(JSON.stringify).join(',') + ')';
}
}
};
cxName: function(attr) {
if (attr.value.type !== Syntax.Literal) {
throw new Error("cx only accepts a string literal");
} else {
var classNames = attr.value.value.split(/\s+/g);
return 'cx(' + classNames.map(JSON.stringify).join(',') + ')';
}
}
};
object.children.forEach(function(child, index) {
if (child.type === Syntax.Literal) {
codemodXJSLiteral(child, state);
} else if (child.type === Syntax.XJSExpressionContainer) {
var isNotAfterLiteral =
index == 0 ||
object.children[index - 1].type !== Syntax.Literal;
var isNotBeforeLiteral =
index == object.children.length - 1 ||
object.children[index + 1].type !== Syntax.Literal;
codemodXJSExpressionContainer(
traverse,
child,
isNotAfterLiteral,
isNotBeforeLiteral,
path,
state
);
} else {
traverse(child, path, state);
}
children.forEach(function(child) {
if (child.type === Syntax.Literal) {
utils.append(state.currentParent + '.appendChild(document.createTextNode("' + child.raw + '"));\n', state);
} else {
traverse(child, path, state);
}
utils.move(child.range[1], state);
});
childrenToRender.forEach(function(child, index) {
utils.catchup(child.range[0], state, trimLeft);
var isLast = index >= lastRenderableIndex;
if (child.type === Syntax.Literal) {
renderJSXLiteral(child, isLast, state);
} else if (child.type === Syntax.JSXExpressionContainer) {
renderJSXExpressionContainer(traverse, child, isLast, path, state);
} else {
traverse(child, path, state);
if (!isLast) {
utils.append(', ', state);
}
}
utils.catchup(child.range[1], state, trimLeft);
});
}
object.children.forEach(function(child) {
if (child.type === Syntax.Literal && !child.value.match(/\S/)) {
return;
}
utils.catchup(child.range[0], state);
var isLast = child === childrenToRender[childrenToRender.length - 1];
if (child.type === Syntax.Literal) {
renderXJSLiteral(child, isLast, state);
} else if (child.type === Syntax.XJSExpressionContainer) {
renderXJSExpressionContainer(traverse, child, isLast, path, state);
} else {
utils.traverse(child, path, state);
if (!isLast) {
utils.append(',', state);
state.g.buffer = state.g.buffer.replace(/(\s*),$/, ',$1');
}
}
utils.catchup(child.range[1], state);
});
}