Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return {
type: "Resolve",
node: getExpressionNodeFromCommentValue(match[1])
};
} else if (PROMISE_REJECT_COMMENT_PATTERN.test(message)) {
const match = message.match(PROMISE_REJECT_COMMENT_PATTERN);
if (!match) {
throw new Error("Can not Parse: // => Reject: value");
}
return {
type: "Reject",
node: getExpressionNodeFromCommentValue(match[1])
};
}
try {
return parseExpression(string);
} catch (e) {
console.error(`Can't parse comments // => expression`);
throw e;
}
}
function getExports(node, counter) {
const { value, type } = node;
if (type === 'jsx') {
if (STORY_REGEX.exec(value)) {
// Single story
const ast = parser.parseExpression(value, { plugins: ['jsx'] });
const storyExport = genStoryExport(ast, counter);
return storyExport && { stories: storyExport };
}
if (PREVIEW_REGEX.exec(value)) {
// Preview, possibly containing multiple stories
const ast = parser.parseExpression(value, { plugins: ['jsx'] });
return { stories: genPreviewExports(ast, counter) };
}
if (META_REGEX.exec(value)) {
// Preview, possibly containing multiple stories
const ast = parser.parseExpression(value, { plugins: ['jsx'] });
return { meta: genMeta(ast) };
}
}
return null;
}
function getStories(node, counter) {
const { value, type } = node;
// Single story
if (type === 'jsx') {
if (STORY_REGEX.exec(value)) {
// Single story
const ast = parser.parseExpression(value, { plugins: ['jsx'] });
const storyExport = genStoryExport(ast, value, counter);
return storyExport && [storyExport];
}
if (PREVIEW_REGEX.exec(value)) {
// Preview, possibly containing multiple stories
const ast = parser.parseExpression(value, { plugins: ['jsx'] });
return genPreviewExports(ast, value, counter);
}
}
return null;
}
function getExports(node, counter) {
const { value, type } = node;
if (type === 'jsx') {
if (STORY_REGEX.exec(value)) {
// Single story
const ast = parser.parseExpression(value, { plugins: ['jsx'] });
const storyExport = genStoryExport(ast, counter);
return storyExport && { stories: storyExport };
}
if (PREVIEW_REGEX.exec(value)) {
// Preview, possibly containing multiple stories
const ast = parser.parseExpression(value, { plugins: ['jsx'] });
return { stories: genPreviewExports(ast, counter) };
}
if (META_REGEX.exec(value)) {
// Preview, possibly containing multiple stories
const ast = parser.parseExpression(value, { plugins: ['jsx'] });
return { meta: genMeta(ast) };
}
}
return null;
}
function getStories(node, counter) {
const { value, type } = node;
// Single story
if (type === 'jsx') {
if (STORY_REGEX.exec(value)) {
// Single story
const ast = parser.parseExpression(value, { plugins: ['jsx'] });
const storyExport = genStoryExport(ast, value, counter);
return storyExport && [storyExport];
}
if (PREVIEW_REGEX.exec(value)) {
// Preview, possibly containing multiple stories
const ast = parser.parseExpression(value, { plugins: ['jsx'] });
return genPreviewExports(ast, value, counter);
}
}
return null;
}
let item;
while (i < length) {
item = array[i++];
if (previousWasTextNode === true) {
str += "" + item;
} else {
str += item;
}
previousWasTextNode = item[0] !== "<";
}
return str;
}
`;
let escapeHelperAst = parseExpression(arrayHelper, { plugins: ["flow"] });
let helper = new ECMAScriptSourceFunctionValue(realm);
helper.initialize(escapeHelperAst.params, escapeHelperAst.body);
return helper;
}
function valueToAST(value: unknown, type: parameterType) {
if (value === undefined) {
return identifier('undefined');
}
if (type === 'identifier' && typeof value === 'string') {
return identifier(value);
}
switch (typeof value) {
case 'string':
return stringLiteral(value);
case 'number':
return numericLiteral(value);
case 'boolean':
return booleanLiteral(value);
case 'object': {
return parseExpression(JSON.stringify(value));
}
default:
throw Error(`Unknown type ${type}`);
}
}
const css = objToString(styles, isDev)
const parent = path.parentPath
if (parent.isTemplateLiteral()) {
const exprIndex = parent.get('expressions').indexOf(path)
const before = parent.get('quasis')[exprIndex]
const after = parent.get('quasis')[exprIndex + 1]
after.node.value.raw = before.node.value.raw + css + after.node.value.raw
after.node.value.cooked =
before.node.value.cooked + css + after.node.value.cooked
before.remove()
path.remove()
const ast = babylon.parseExpression(generate(parent.node).code)
parent.replaceWith(ast)
} else {
const tte = '`' + css + '`'
path.replaceWith(babylon.parseExpression(tte))
}
} else {
if (path.node.type === 'StringLiteral') {
path.replaceWith(t.callExpression(cloneNode(cssIdentifier), [styleObj]))
} else {
path.replaceWith(styleObj)
}
}
}
asArray(replace).forEach(([key, value]) => {
const kNode = parseExpression(key);
const vNode = parseExpression(value);
const candidates = types.get(kNode.type) || [];
candidates.push({ key: kNode, value: vNode, originalKey: key });
types.set(kNode.type, candidates);
for (let i = 0; i < candidates.length - 1; i++) {
if (!t.isNodesEquivalent(candidates[i].key, kNode)) {
continue;
}
if (allowConflictingReplacements) {
candidates[i] = candidates.pop();
break;
}
function buildSecurityConfig(opSecurity, defaultSecurity, securityDefinitions) {
let securityConfig = {};
const security = opSecurity || defaultSecurity;
if (security && security.length) {
const auths = new Set();
security.forEach(schemas =>
Object.keys(schemas).forEach(auth => auths.add(auth))
);
securityConfig = {
security: security,
definitions: pick(securityDefinitions, Array.from(auths)),
};
}
return parser.parseExpression(JSON.stringify(securityConfig));
}