Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
key
),
value
)))
path.remove()
}
})
for (const method of mainClass.body.body) {
// constructor 即便没有被定义也会被加上
if (t.isClassMethod(method) && method.kind === 'constructor') {
const index = method.body.body.findIndex(node => t.isSuper(node))
method.body.body.push(
t.expressionStatement(t.assignmentExpression(
'=',
t.memberExpression(
t.thisExpression(),
t.identifier('state')
),
t.callExpression(t.memberExpression(t.thisExpression(), t.identifier('_createData')), [])
))
)
method.body.body.splice(index, 0, ...statements)
}
}
let code = `function f() {};` +
generate(t.classDeclaration(t.identifier('Test'), t.identifier('f'), mainClass.body, [])).code +
';' + `new Test(${props})`
code = internalFunction + code
t.variableDeclaration('var', [
t.variableDeclarator(
t.identifier(declarationName),
t.objectExpression([])
)
])
);
}
// 初始化 _global
path.pushContainer(
'body',
t.expressionStatement(
t.assignmentExpression(
'=',
t.memberExpression(
t.identifier(declarationName),
t.identifier('_global')
),
t.objectExpression([])
)
)
);
Object.keys(scope.getAllBindings()).forEach(key => {
path.pushContainer(
'body',
t.expressionStatement(
t.assignmentExpression(
'=',
t.memberExpression(
t.memberExpression(
}
}
pushProps();
if (objs.length === 1) {
// only one object
attribs = objs[0];
} else {
// looks like we have multiple objects
if (!t.isObjectExpression(objs[0])) {
objs.unshift(t.objectExpression([]));
}
const helper = useBuiltIns ?
t.memberExpression(t.identifier("Object"), t.identifier("assign")) :
file.addHelper("extends");
// spread it
attribs = t.callExpression(helper, objs);
}
return attribs;
}
}
function appCallCC(receiver: t.Expression) {
return t.callExpression(
t.memberExpression(t.identifier("$__R"), t.identifier("callCC")),
[receiver]);
}
function getRuntimeMarkDecl(blockPath) {
let block = blockPath.node;
assert.ok(Array.isArray(block.body));
let info = getMarkInfo(block);
if (info.decl) {
return info.decl;
}
info.decl = t.variableDeclaration("var", [
t.variableDeclarator(
blockPath.scope.generateUidIdentifier("marked"),
t.callExpression(
t.memberExpression(
t.arrayExpression([]),
t.identifier("map"),
false
),
[util.runtimeProperty("mark")]
)
)
]);
blockPath.unshiftContainer("body", info.decl);
return info.decl;
}
return path.isProgram() || path.isBlockStatement();
});
if (!pp) {
return node.id;
}
let markDecl = getRuntimeMarkDecl(pp);
let markedArray = markDecl.declarations[0].id;
let funDeclIdArray = markDecl.declarations[0].init.callee.object;
t.assertArrayExpression(funDeclIdArray);
let index = funDeclIdArray.elements.length;
funDeclIdArray.elements.push(node.id);
return t.memberExpression(
markedArray,
t.numericLiteral(index),
true
);
}
return node.id;
}
const getSubFinallyExpression = function(proxyIdentifier, subIdentifier){
const disposeExpression = t.callExpression(
t.memberExpression(subIdentifier, t.identifier('dispose')),
[]
)
let observersCount = t.memberExpression(proxyIdentifier, t.identifier('observers.length'));
const condition = t.ifStatement(
t.binaryExpression("===", observersCount, t.identifier('0')),
t.expressionStatement(disposeExpression)
)
return t.callExpression(
t.memberExpression(proxyIdentifier, t.identifier('finally')),
[t.arrowFunctionExpression([], t.blockStatement([condition]))]
)
}
'method',
t.identifier(Lifecycle.componentWillMount),
[],
t.blockStatement([globalData])
)
)
}
}
const wxsNames = new Set(wxses ? wxses.map(w => w.module) : [])
const renderFunc = buildRender(returned, stateKeys.filter(s => !wxsNames.has(s)), propsKeys)
const classDecl = t.classDeclaration(
t.identifier(componentType === 'App' ? 'App' : defaultClassName),
t.memberExpression(t.identifier('Taro'), t.identifier('Component')),
t.classBody(
classBody.concat(renderFunc)
),
[]
)
if (weappConf) {
classDecl.decorators = [buildDecorator(componentType || 'Page', weappConf)]
}
return classDecl
}
function addHash(exportIdentifier, hash) {
const value = typeof hash === 'string' ? t.stringLiteral(hash) : hash
return t.expressionStatement(
t.assignmentExpression(
'=',
t.memberExpression(exportIdentifier, t.identifier('__hash')),
value
)
)
}