|
|
@ -127,7 +127,6 @@ export default class Component extends Node {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const allContexts = new Set();
|
|
|
|
|
|
|
|
const statements: string[] = [];
|
|
|
|
const statements: string[] = [];
|
|
|
|
|
|
|
|
|
|
|
|
const name_initial_data = block.getUniqueName(`${name}_initial_data`);
|
|
|
|
const name_initial_data = block.getUniqueName(`${name}_initial_data`);
|
|
|
@ -135,10 +134,6 @@ export default class Component extends Node {
|
|
|
|
let name_updating: string;
|
|
|
|
let name_updating: string;
|
|
|
|
let beforecreate: string = null;
|
|
|
|
let beforecreate: string = null;
|
|
|
|
|
|
|
|
|
|
|
|
// const eventHandlers = this.attributes
|
|
|
|
|
|
|
|
// .filter((a: Node) => a.type === 'EventHandler')
|
|
|
|
|
|
|
|
// .map(a => mungeEventHandler(compiler, this, a, block, allContexts));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const updates: string[] = [];
|
|
|
|
const updates: string[] = [];
|
|
|
|
|
|
|
|
|
|
|
|
const usesSpread = !!this.attributes.find(a => a.isSpread);
|
|
|
|
const usesSpread = !!this.attributes.find(a => a.isSpread);
|
|
|
@ -146,7 +141,6 @@ export default class Component extends Node {
|
|
|
|
const attributeObject = usesSpread
|
|
|
|
const attributeObject = usesSpread
|
|
|
|
? '{}'
|
|
|
|
? '{}'
|
|
|
|
: stringifyProps(
|
|
|
|
: stringifyProps(
|
|
|
|
// this.attributes.map(attr => `${attr.name}: ${attr.value}`)
|
|
|
|
|
|
|
|
this.attributes.map(attr => `${attr.name}: ${attr.getValue()}`)
|
|
|
|
this.attributes.map(attr => `${attr.name}: ${attr.getValue()}`)
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
@ -237,10 +231,6 @@ export default class Component extends Node {
|
|
|
|
this.bindings.forEach((binding: Binding) => {
|
|
|
|
this.bindings.forEach((binding: Binding) => {
|
|
|
|
let { name: key } = getObject(binding.value.node);
|
|
|
|
let { name: key } = getObject(binding.value.node);
|
|
|
|
|
|
|
|
|
|
|
|
binding.value.contexts.forEach(context => {
|
|
|
|
|
|
|
|
allContexts.add(context);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let setFromChild;
|
|
|
|
let setFromChild;
|
|
|
|
|
|
|
|
|
|
|
|
if (block.contexts.has(key)) { // TODO remove block.contexts
|
|
|
|
if (block.contexts.has(key)) { // TODO remove block.contexts
|
|
|
@ -492,51 +482,6 @@ export default class Component extends Node {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function mungeEventHandler(compiler: DomGenerator, node: Node, handler: Node, block: Block, allContexts: Set<string>) {
|
|
|
|
|
|
|
|
let body;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (handler.expression) {
|
|
|
|
|
|
|
|
compiler.addSourcemapLocations(handler.expression);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO try out repetition between this and element counterpart
|
|
|
|
|
|
|
|
const flattened = flattenReference(handler.expression.callee);
|
|
|
|
|
|
|
|
if (!validCalleeObjects.has(flattened.name)) {
|
|
|
|
|
|
|
|
// allow event.stopPropagation(), this.select() etc
|
|
|
|
|
|
|
|
// TODO verify that it's a valid callee (i.e. built-in or declared method)
|
|
|
|
|
|
|
|
compiler.code.prependRight(
|
|
|
|
|
|
|
|
handler.expression.start,
|
|
|
|
|
|
|
|
`${block.alias('component')}.`
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let usesState = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handler.expression.arguments.forEach((arg: Node) => {
|
|
|
|
|
|
|
|
const { contexts } = block.contextualise(arg, null, true);
|
|
|
|
|
|
|
|
if (contexts.has('state')) usesState = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
contexts.forEach(context => {
|
|
|
|
|
|
|
|
allContexts.add(context);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
body = deindent`
|
|
|
|
|
|
|
|
${usesState && `const ctx = #component.get();`}
|
|
|
|
|
|
|
|
[✂${handler.expression.start}-${handler.expression.end}✂];
|
|
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
body = deindent`
|
|
|
|
|
|
|
|
#component.fire('${handler.name}', event);
|
|
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
name: handler.name,
|
|
|
|
|
|
|
|
var: block.getUniqueName(`${node.var}_${handler.name}`),
|
|
|
|
|
|
|
|
body
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function isComputed(node: Node) {
|
|
|
|
function isComputed(node: Node) {
|
|
|
|
while (node.type === 'MemberExpression') {
|
|
|
|
while (node.type === 'MemberExpression') {
|
|
|
|
if (node.computed) return true;
|
|
|
|
if (node.computed) return true;
|
|
|
|