Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// console.log(logStr);
//设置默认值
let initialValue;
switch (value.type) {
case "BooleanLiteral":
initialValue = t.booleanLiteral(false);
break;
case "NumericLiteral":
initialValue = t.numericLiteral(0);
break;
case "ArrayExpression":
initialValue = t.arrayExpression();
break;
case "ObjectExpression":
initialValue = t.objectExpression([]);
break;
default:
//其余全是空
initialValue = t.stringLiteral("");
break;
}
vistors.data.handle(t.objectProperty(t.identifier(name), initialValue));
dataJson[name] = name;
} else {
//TODO:
//如果props有个变量abc,使用this.setData({abc:1})会报错,但在小程序里是正确的,
//如果要改的话,要用一个中间变量,并且把页面里所有的地方都要替换,工作量有点繁琐。
}
}
}
find(attr, setValue) {
const attrName = attrUtil(attr).name();
const valueExpr = attrUtil(attr).valueExpr();
/* istanbul ignore next: print warn info */
if (attrName === 'style') {
if (t.isStringLiteral(valueExpr)) {
codeFrameWarn(
attr,
'The `style` prop expected a mapping from style properties to values, not a string. For example, style={{marginRight: spacing + \'em\'}}'
);
} else {
setValue(t.objectExpression([
t.objectProperty(
t.identifier('style'),
valueExpr
)
]));
}
return true;
}
/* istanbul ignore next: print warn info */
if (/^(style)$/i.test(attrName)) {
codeFrameWarn(
attr,
`Non-lowercase \`style\` prop will be ignored, when use \`${DIRECTIVES.SHOW}\``
);
return true;
for (let directive of func.body.directives) {
if (directive.value.value === "use strict") {
// already have a use strict directive
continue funcLoop;
}
}
} else func.body.directives = [];
func.body.directives.unshift(strictDirective);
}
}
}
// build ast
if (this.needsEmptyVar) {
this.prelude.push(t.variableDeclaration("var", [t.variableDeclarator(emptyExpression, t.objectExpression([]))]));
}
if (this.needsAuxiliaryConstructor) {
this.prelude.push(
t.variableDeclaration("var", [
t.variableDeclarator(constructorExpression, t.functionExpression(null, [], t.blockStatement([]))),
])
);
}
let body = this.prelude.concat(this.emitter.getBody().entries);
factorifyObjects(body, this.factoryNameGenerator);
let ast_body = [];
if (this.preludeGenerator.declaredGlobals.size > 0)
ast_body.push(
t.variableDeclaration(
const dataPath = path.get('arguments.1')
if (dataPath && dataPath.isObjectExpression()) {
const attrsProperty = dataPath.node.properties.find(property => property.key.name === 'attrs')
if (attrsProperty) {
attrsProperty.value.properties.unshift(objectProperty)
} else {
dataPath.node.properties.push(
t.objectProperty(t.identifier('attrs'), t.objectExpression([
objectProperty
]))
)
}
} else { // {attrs:{'vue-id':'2'}}
const args = path.node.arguments
args.splice(1, 0, t.objectExpression(
[
t.objectProperty(t.identifier('attrs'), t.objectExpression([
objectProperty
]))
]
))
}
}
ReferencedIdentifier(path) {
let {name} = path.node;
if (typeof name !== 'string') {
return;
}
if (imports.has(name)) {
let imp = imports.get(name);
let node = replaceExportNode(imp[0], imp[1], path);
// If the export does not exist, replace with an empty object.
if (!node) {
node = t.objectExpression([]);
}
path.replaceWith(node);
return;
}
let match = name.match(EXPORTS_RE);
if (match) {
referenced.add(name);
}
// If it's an undefined $id$exports identifier.
if (match && !path.scope.hasBinding(name)) {
path.replaceWith(t.objectExpression([]));
}
},
throw new Error(
"transform-react-jsx currently only accepts a boolean option for " +
"useBuiltIns (defaults to false)",
);
}
if (useSpread && useBuiltIns) {
throw new Error(
"transform-react-jsx currently only accepts useBuiltIns or useSpread " +
"but not both",
);
}
if (useSpread) {
const props = attribs.map(convertAttribute);
return t.objectExpression(props);
}
while (attribs.length) {
const prop = attribs.shift();
if (t.isJSXSpreadAttribute(prop)) {
_props = pushProps(_props, objs);
objs.push(prop.argument);
} else {
_props.push(convertAttribute(prop));
}
}
pushProps(_props, objs);
if (objs.length === 1) {
// only one object
const propMaps = [];
props && Object.keys(props).forEach(key => {
const value = props[key];
propMaps.push(t.objectProperty(
t.stringLiteral(key),
value
));
});
let argPIDExp = tagIdExpression
? genTagIdExp(tagIdExpression)
: t.stringLiteral(tagId);
const updatePropsArgs = [
argPIDExp,
t.objectExpression(propMaps)
];
const callUpdateProps = t.expressionStatement(t.callExpression(updateProps, updatePropsArgs));
if (propMaps.length > 0) {
const targetNode = parentNode || fnBody;
if (t.isReturnStatement(targetNode[targetNode.length - 1])) {
targetNode.splice(targetNode.length - 1, 0, callUpdateProps);
} else {
targetNode.push(callUpdateProps);
}
} else if ((parentNode || fnBody).length === 0) {
// Remove empty loop exp.
parentNode && parentNode.remove && parentNode.remove();
}
});
addUpdateData(dynamicValue, renderItemFunctions, renderFunctionPath);
function pushProps(_props, objs) {
if (!_props.length) return _props;
objs.push(t.objectExpression(_props));
return [];
}
}
}
const exportsIdentifier = generateUidIdentifier(
programPath.scope,
'defaultExport'
);
const firstStatement = getEnclosingStatement(exportPaths[0]);
const lastStatement = getEnclosingStatement(
exportPaths[exportPaths.length - 1]
);
lastStatement.scope.registerDeclaration(
firstStatement.insertBefore(
t.variableDeclaration('var', [
t.variableDeclarator(exportsIdentifier, t.objectExpression([]))
])
)[0]
);
for (const exportPath of exportPaths) {
replaceWithAndPreserveComments(exportPath, exportsIdentifier);
}
lastStatement.insertAfter(t.exportDefaultDeclaration(exportsIdentifier));
}
if (extractComments) {
const hasDescription = messageDescriptorProperties.find(
v => v.key.name === 'description'
)
if (!hasDescription) {
const description = getLeadingComment(prop)
if (description) {
messageDescriptorProperties.push(
objectProperty('description', description)
)
}
}
}
objectValuePath.replaceWith(t.objectExpression(messageDescriptorProperties))
}
}