Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
isComputed
);
});
const quasis = classNames.map(() =>
t.templateElement({ cooked: " ", raw: " " })
); // Spaces between
quasis.pop();
quasis.push(t.templateElement({ cooked: "", raw: "" }, true)); // End of template string
quasis.unshift(t.templateElement({ cooked: "", raw: "" })); // Empty string before
return t.templateLiteral(quasis, expressions);
} else {
const isComputed = className.includes("-");
return isCssModules
? t.MemberExpression(
t.identifier("styles"),
isComputed ? t.stringLiteral(className) : t.identifier(className),
isComputed
)
: t.StringLiteral(className);
}
};
// main function declaration
let expr = t.functionDeclaration(
t.identifier(opts.main),
[t.identifier(ELEM)],
t.blockStatement(
[
t.returnStatement(
t.callExpression(
t.memberExpression(
t.memberExpression(
t.identifier(opts.templates),
t.callExpression(
t.memberExpression(
t.memberExpression(
t.identifier(ELEM),
t.identifier(TAG_NAME)
),
t.identifier(TO_LOWER_CASE)
),
[]
),
true
),
t.identifier('call')
),
[t.identifier(ELEM), t.identifier(ELEM)]
)
)
]
)
);
xp.forOptimization = (
ast: AST,
names: Array,
dependencyMapName?: string,
) =>
collectDependencies(
ast,
new ProdReplacement(names),
dependencyMapName ? types.identifier(dependencyMapName) : undefined,
);
}
newProperties.push(
t.property(
'init',
t.identifier('className'),
t.literal(value)
)
);
} else if (t.isCallExpression(value) && value.callee.name === '__cx') {
newProperties.push(
t.property(
'init',
t.identifier('className'),
t.callExpression(
t.identifier('__cx'),
value.arguments.concat(t.literal(className))
)
)
);
} else {
newProperties.push(
t.property(
'init',
t.identifier('className'),
t.callExpression(
t.identifier('__cx'),
[value, t.literal(className)]
)
)
);
}
t.memberExpression(
t.memberExpression(
t.identifier(opts.templates),
t.callExpression(
t.memberExpression(
t.memberExpression(
t.identifier(ELEM),
t.identifier(TAG_NAME)
),
t.identifier(TO_LOWER_CASE)
),
[]
),
true
),
t.identifier('call')
),
[t.identifier(ELEM), t.identifier(ELEM)]
)
)
]
)
);
return t.program([expr]);
}
export default function compile(quasi, node) {
t.assertTemplateLiteral(node)
const strings = node.quasis.map((child) => child.value.raw)
const source = concat(strings)
const ast = parse(source)
const replacement = transformer.run(ast, {
arguments: node.expressions,
})
return t.functionExpression(null, [t.identifier('params')], t.blockStatement([
t.variableDeclaration('const', [
t.variableDeclarator(t.identifier('GraphQL'), t.memberExpression(quasi, t.identifier('GraphQL'))),
]),
t.returnStatement(replacement),
]))
}
'use strict';
const t = require('babel-core').types;
const { prop, set, has, flow, findIndex } = require('lodash/fp');
const { manipulateOptions } = require('./common');
const WARNING =
'An injectGlobal usage was converted to createGlobalStyles via codemod but needs to be hooked up. See https://www.styled-components.com/docs/api#createglobalstyle for instructions.';
const PREVIOUS = 'injectGlobal';
const NEXT = 'createGlobalStyle';
const COMPONENT_ID = t.identifier('GlobalStyle');
const NEXT_ID = t.identifier(NEXT);
const EXPRESSION = 'node.expression';
const paths = {
global: 'node.expression.tag.name',
obj: 'node.expression.tag.property.name',
};
const isInjectGlobalCall = path =>
prop(paths.global)(path) === PREVIOUS || prop(paths.obj)(path) === PREVIOUS;
const isInjectGlobalProp = property =>
property.shorthand === true && property.key.name === 'injectGlobal';
let shouldAddWarning = false;
module.exports = () => ({