Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exit(path) {
if (!path.isReferenced()) {
return;
}
let {object, property, computed} = path.node;
if (
!(
t.isIdentifier(object) &&
((t.isIdentifier(property) && !computed) ||
t.isStringLiteral(property))
)
) {
return;
}
let match = object.name.match(EXPORTS_RE);
// If it's a $id$exports.name expression.
if (match) {
let name = t.isIdentifier(property) ? property.name : property.value;
let {identifier} = packager.findExportModule(
match[1],
name,
replacements,
);
function generateConditionValue(test, options) {
let conditionValue;
if (/Expression$/.test(test.type)) {
conditionValue = t.jsxExpressionContainer(test);
} else if (t.isStringLiteral(test)) {
conditionValue = test;
} else {
// Other literal types or identifier.
conditionValue = t.stringLiteral(createBinding(genExpression(test)));
if (t.isIdentifier(test)) options.dynamicValue[test.name] = test;
}
return conditionValue;
}
args.length === 1 &&
types.isStringLiteral(args[0]) &&
!hasBinding(ancestors, 'require') &&
!isInFalsyBranch(ancestors);
if (isRequire) {
let isOptional =
ancestors.some(a => types.isTryStatement(a)) || undefined;
addDependency(asset, args[0], {isOptional});
return;
}
let isDynamicImport =
callee.type === 'Import' &&
args.length === 1 &&
types.isStringLiteral(args[0]);
if (isDynamicImport) {
// Ignore dynamic imports of fully specified urls
if (isURL(args[0].value)) {
return;
}
addDependency(asset, args[0], {isAsync: true});
node.callee = types.identifier('require');
invariant(asset.ast);
asset.ast.isDirty = true;
return;
}
const isRegisterServiceWorker =
CallExpression(path, file) {
if (doNotTraverse)
return;
try {
if (t.isMemberExpression(path.node.callee) &&
path.node.callee.property.name == "createElement" &&
check_1.check.isFidanCall(path.node)) {
const firstArgument = path.node.arguments[0];
const secondArgument = path.node.arguments.length > 1 ? path.node.arguments[1] : null;
if (t.isStringLiteral(firstArgument)) {
if (check_1.check.isSvgElementTagName(firstArgument.value, openedTags))
path.node.callee.property.name = "createSvgElement";
}
let jsxFactoryName = null;
if (t.isIdentifier(firstArgument)) {
let variableBinding = found_1.found.variableBindingInScope(path.scope, firstArgument.name);
if (variableBinding &&
t.isImportDeclaration(variableBinding.path.parent)) {
const importPath = variableBinding.path.parent.source.value;
if (this.opts.exclude &&
micromatch(importPath + ".", this.opts.exclude, {
matchBase: true
}).length) {
jsxFactoryName = importPath.substr(importPath.lastIndexOf(".") + 1);
}
}
//这里没法调babelUtil.globalDataHandle(),子节点没有replaceWidth方法了(或许有转换方法,暂未知)
let getApp = t.callExpression(t.identifier('getApp'), []);
let subMe = t.MemberExpression(t.MemberExpression(getApp, t.identifier('globalData')), subProperty);
let me = t.MemberExpression(subMe, property);
let vd = t.variableDeclarator(path2.node.id, me);
path.replaceWith(vd);
path.skip();
}
} else if (t.isCallExpression(path2.node.init)) {
//处理外部声明的require,如var md5 = require("md5.js");
const initPath = path2.node.init;
let callee = initPath.callee;
if (t.isIdentifier(callee, { name: "require" })) {
let arguments = initPath.arguments;
if (arguments && arguments.length) {
if (t.isStringLiteral(arguments[0])) {
let filePath = arguments[0].value;
filePath = pathUtil.relativePath(filePath, global.miniprogramRoot, fileDir);
initPath.arguments[0] = t.stringLiteral(filePath);
}
}
}
} else if (t.isThisExpression(path2.node.init)) {
//记录当前文件里使用过的this别名
if (!global.pagesData[fileKey]) global.pagesData[fileKey] = {};
if (!global.pagesData[fileKey]["thisNameList"]) global.pagesData[fileKey]["thisNameList"] = [];
global.pagesData[fileKey]["thisNameList"].push(2)
}
}
});
export default (
path: *,
styleModuleImportMap: StyleModuleImportMapType,
sourceAttribute: JSXAttribute,
destinationName: string,
options: GetClassNameOptionsType
): void => {
const resolvedStyleName = getClassName(sourceAttribute.value.value, styleModuleImportMap, options);
const destinationAttribute = path.node.openingElement.attributes
.find((attribute) => {
return typeof attribute.name !== 'undefined' && attribute.name.name === destinationName;
});
if (destinationAttribute) {
if (isStringLiteral(destinationAttribute.value)) {
destinationAttribute.value.value += ' ' + resolvedStyleName;
} else if (isJSXExpressionContainer(destinationAttribute.value)) {
destinationAttribute.value.expression = conditionalClassMerge(
destinationAttribute.value.expression,
stringLiteral(resolvedStyleName)
);
} else {
throw new Error('Unexpected attribute value:' + destinationAttribute.value);
}
path.node.openingElement.attributes.splice(path.node.openingElement.attributes.indexOf(sourceAttribute), 1);
} else {
sourceAttribute.name.name = destinationName;
sourceAttribute.value.value = resolvedStyleName;
}
};
function pushResult(value, result) {
const len = result.length;
if (len) {
const lastIdx = len - 1;
const lastChild = result[lastIdx];
if (isStringObject(lastChild)) {
if (isStringObject(value)) {
updateStringObject(lastChild, value.properties[0].value.value);
} else if (t.isStringLiteral(value)) {
updateStringObject(lastChild, value.value);
} else {
result.push(value);
}
} else if (t.isStringLiteral(value)) {
result.push(buildObject(KEY_FOR_HTML, value));
} else {
result.push(value);
}
} else if (t.isStringLiteral(value)) {
result.push(buildObject(KEY_FOR_HTML, value));
} else {
result.push(value);
}
}
(node.operator === '===' || node.operator === '!==') &&
(t.isStringLiteral(node.right) || t.isStringLiteral(node.left))
) {
const propType = this.types.find(obj =>
obj.matches.some(
item =>
(obj.isRequired || item.hasDefaultValue) &&
(helpers.compareNodes(node.left, item) || helpers.compareNodes(node.right, item)),
),
);
if (propType === undefined) return;
const valueToUse =
propType.optionA.length < propType.optionB.length ? propType.optionA : propType.optionB;
const target = t.isStringLiteral(node.right) ? 'right' : 'left';
if (
node[target].value !== valueToUse &&
(node[target].value === propType.optionA || node[target].value === propType.optionB)
) {
node[target] = t.stringLiteral(valueToUse);
node.operator = node.operator === '!==' ? '===' : '!==';
}
}
},
};
export function extractMessageIdFromNode(node) {
if (!isStringLiteral(node)) {
throw createFailError(`Message id should be a string literal.`);
}
return node.value;
}