Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Transform:
// import('./some/module.js')
// Into:
// import('./bundle_1.js')
// .then(({ $bundled$some$module }) => $bundled$some$module)
const importCallExpression = babelUtils.getParentNode(astRoot, jsImport);
if (!importCallExpression ||
!babel.isCallExpression(importCallExpression)) {
// TODO(usergenic): This log should be a real error or warning or
// something.
console.log(
'CAN NOT INSERT CODE BECAUSE CAN NOT FIND PARENT OF IMPORT IN DOCUMENT AST');
continue;
}
const importCallArgument = importCallExpression.arguments[0]!;
if (!babel.isStringLiteral(importCallArgument)) {
console.log(
'CAN NOT FIGURE OUT WHERE THE DYNAMIC IMPORT IS PULLING FROM. I ONLY UNDERSTAND STRING LITERALS');
continue;
}
const sourceUrl = importCallArgument.value;
const resolvedSourceUrl =
urlLib.resolve(docBundle.url, sourceUrl) as ResolvedUrl;
const sourceBundle = bundleManifest.getBundleForFile(resolvedSourceUrl);
if (sourceBundle && sourceBundle.url !== resolvedSourceUrl) {
const exportedName = getOrSet(
docBundle.bundle.exportedJsModules,
resolvedSourceUrl,
() => exportedJsModuleNameFn(sourceBundle.url, resolvedSourceUrl));
importCallExpression.arguments[0] = babel.stringLiteral(
urlUtils.relativeUrl(docBundle.url, sourceBundle.url));
if (path.parentPath.isTaggedTemplateExpression()) {
return;
}
for (const elem of quasis) {
if (elem.value.cooked) {
nodes.push(t.stringLiteral(elem.value.cooked));
}
if (index < expressions.length) {
const expr = expressions[index++];
if (!t.isStringLiteral(expr, { value: '' })) {
nodes.push(expr);
}
}
}
// + 号连接符必须保证第一和第二个 node 都是字符串
if (!t.isStringLiteral(nodes[0]) && !t.isStringLiteral(nodes[1])) {
nodes.unshift(t.stringLiteral(''));
}
let root = nodes[0];
for (let i = 1; i < nodes.length; i++) {
root = t.binaryExpression('+', root, nodes[i]);
}
path.replaceWith(root);
},
ClassDeclaration(path) {
bodyBlockPath.get("body").forEach(function(childPath) {
let node = childPath.node;
if (t.isExpressionStatement(node) &&
t.isStringLiteral(node.expression)) {
// Babylon represents directives like "use strict" as elements
// of a bodyBlockPath.node.directives array, but they could just
// as easily be represented (by other parsers) as traditional
// string-literal-valued expression statements, so we need to
// handle that here. (#248)
outerBody.push(node);
} else if (node && node._blockHoist != null) {
outerBody.push(node);
} else {
innerBody.push(node);
}
});
TemplateLiteral(path) {
const nodes = [];
const { quasis, expressions } = path.node;
let index = 0;
if (path.parentPath.isTaggedTemplateExpression()) {
return;
}
for (const elem of quasis) {
if (elem.value.cooked) {
nodes.push(t.stringLiteral(elem.value.cooked));
}
if (index < expressions.length) {
const expr = expressions[index++];
if (!t.isStringLiteral(expr, { value: '' })) {
nodes.push(expr);
}
}
}
// + 号连接符必须保证第一和第二个 node 都是字符串
if (!t.isStringLiteral(nodes[0]) && !t.isStringLiteral(nodes[1])) {
nodes.unshift(t.stringLiteral(''));
}
let root = nodes[0];
for (let i = 1; i < nodes.length; i++) {
root = t.binaryExpression('+', root, nodes[i]);
}
path.replaceWith(root);
},
ClassDeclaration(path) {
}
debug(`function call "${callFuncName}" is found:`, node.arguments[0].value);
let args0 = node.arguments[0];
let theRight;
let theLeft;
let flagRequireWithVar = false;
// check if Binary express, like `load('./abc' + vars + '.js');`
if (babelType.isBinaryExpression(args0)) {
flagRequireWithVar = true;
// get the right and the
theRight = args0.right;
theLeft = getTheLeftNode(args0);
if (babelType.isStringLiteral(theLeft)) {
// 处理left前缀
fixLeftPart(self, root, filepath, theLeft, config.release/*, requiresMap*/, remote);
}
if (babelType.isStringLiteral(theRight)) {
// 处理right后缀,
fixRightPart(self, root, filepath, theRight, config.release/*, requiresMap*/);
}
} else if (babelType.isTemplateLiteral(args0)) {
flagRequireWithVar = true;
theLeft = args0.quasis[0];
theRight = args0.quasis[args0.quasis.length - 1];
if (theLeft.value.raw) {
fixLeftPart(self, root, filepath, theLeft, config.release/*, requiresMap*/, remote);
}
if (theRight.value.raw) {
fixRightPart(self, root, filepath, theRight, config.release/*, requiresMap*/);
if (name === 'Provider') {
const modules = path.scope.getAllBindings('module');
const providerBinding = Object.values(modules).some((m) => m.identifier.name === 'Provider');
if (providerBinding) {
path.node.name = t.jSXIdentifier('view');
const store = path.node.attributes.find(attr => attr.name.name === 'store');
if (store && t.isJSXExpressionContainer(store.value) && t.isIdentifier(store.value.expression)) {
storeName = store.value.expression.name;
}
path.node.attributes = [];
}
}
if (constant_1.IMAGE_COMPONENTS.has(name)) {
for (const attr of path.node.attributes) {
if (attr.name.name === 'src') {
if (t.isStringLiteral(attr.value)) {
imageSource.add(attr.value.value);
}
else if (t.isJSXExpressionContainer(attr.value)) {
if (t.isStringLiteral(attr.value.expression)) {
imageSource.add(attr.value.expression.value);
}
}
}
}
}
},
JSXAttribute(path) {
return elements.reduce((memo, element) => {
const prevIdx = memo.length - 1;
const prev = memo[prevIdx];
if (t.isStringLiteral(prev) && t.isStringLiteral(element)) {
prev.value += element.value;
} else {
memo.push(element);
}
return memo;
}, []);
};
if (attribute.type === "SPREAD") {
astAttributes.push(t.jSXSpreadAttribute(expr));
} else if (attribute.type === "PROPERTY") {
let attributeKey = attribute.key;
invariant(typeof attributeKey === "string");
astAttributes.push(convertKeyValueToJSXAttribute(attributeKey, expr));
}
}
let astChildren = [];
for (let child of children) {
let expr = ((child.expr: any): BabelNodeExpression);
if (child.type === "NORMAL") {
if (t.isStringLiteral(expr) || t.isNumericLiteral(expr)) {
astChildren.push(t.jSXText(((expr: any).value: string) + ""));
} else if (t.isJSXElement(expr)) {
astChildren.push(expr);
} else {
astChildren.push(t.jSXExpressionContainer(expr));
}
}
}
let openingElement = t.jSXOpeningElement(jsxTypeIdentifer, (astAttributes: any), astChildren.length === 0);
let closingElement = t.jSXClosingElement(jsxTypeIdentifer);
let jsxElement = t.jSXElement(openingElement, closingElement, astChildren, astChildren.length === 0);
this._addBailOutMessageToBabelNode(val, jsxElement);
return jsxElement;
}
function traverseEs5Extend(path, config) {
var callee = path.parent.callee;
if(callee) {
var o = callee.object
extendClass = _getWholeName(o);
var extendArguments = path.parent.arguments;
var arg0,
arg1;
if (extendArguments.length === 1 && t.isObjectExpression(arg0)) {
arg0 = extendArguments[0];
}
else if(t.isStringLiteral(arg0)){
}
var arg0 = "",
arg1;
if(extendArguments.length) {
if(extendArguments.length === 1 && t.isObjectExpression(extendArguments[0])) {
arg1 = extendArguments[0];
}
else if(extendArguments.length === 2) {
if(t.isStringLiteral(extendArguments[0]) && t.isObjectExpression(extendArguments[1])) {
arg0 = extendArguments[0];
arg1 = extendArguments[1];
}
}
else {
function isRequire(node, filename) {
if (
t.isCallExpression(node) &&
t.isIdentifier(node.callee, {name: 'require'}) &&
node.arguments.length === 1 &&
t.isStringLiteral(node.arguments[0])
) {
var relative = node.arguments[0].value;
var fullPath = resolve.sync(relative, {basedir: dirname(filename)});
return {relative: relative, fullPath: fullPath};
} else {
return false;
}
}