use context in event handlers regardless of dependencies

pull/1367/head
Rich Harris 6 years ago
parent 041ad806ee
commit b73a3f6b1a

@ -29,15 +29,16 @@ export default class EventHandler extends Node {
this.callee = flattenReference(info.expression.callee);
this.insertionPoint = info.expression.start;
this.usesComponent = !validCalleeObjects.has(this.callee.name);
this.usesContext = false;
this.args = info.expression.arguments.map(param => {
const expression = new Expression(compiler, this, scope, param);
addToSet(this.dependencies, expression.dependencies);
if (expression.usesContext) this.usesContext = true;
return expression;
});
this.usesComponent = !validCalleeObjects.has(this.callee.name);
this.usesContext = this.dependencies.size > 0;
this.snippet = `[✂${info.expression.start}-${info.expression.end}✂]`;
} else {
this.callee = null;

@ -9,6 +9,7 @@ export default class Expression {
node: any;
snippet: string;
usesContext: boolean;
references: Set<string>;
dependencies: Set<string>;
contexts: Set<string>;
@ -29,6 +30,7 @@ export default class Expression {
this.snippet = `[✂${info.start}-${info.end}✂]`;
this.usesContext = false;
const contextDependencies = new Map(); // TODO
const indexes = new Map();
@ -39,7 +41,7 @@ export default class Expression {
let { map, scope: currentScope } = createScopes(info);
const isEventHandler = parent.type === 'EventHandler';
const { thisReferences } = this;
const expression = this;
walk(info, {
enter(node: any, parent: any, key: string) {
@ -55,7 +57,7 @@ export default class Expression {
}
if (node.type === 'ThisExpression') {
thisReferences.push(node);
expression.thisReferences.push(node);
}
if (isReference(node, parent)) {
@ -72,6 +74,8 @@ export default class Expression {
return;
}
expression.usesContext = true;
code.prependRight(node.start, key === 'key' && parent.shorthand
? `${name}: ctx.`
: 'ctx.');

Loading…
Cancel
Save