From 4f630058fec600a9cc52983d24b17a6e57efe7ca Mon Sep 17 00:00:00 2001 From: Chris Reeves Date: Fri, 25 Jan 2019 18:56:57 -0500 Subject: [PATCH] check module scope when determining if a name is contextual - fixes #2001 --- src/compile/nodes/shared/Expression.ts | 15 ++++++++++++++- .../_config.js | 3 +++ .../module-context-with-instance-script/main.html | 9 +++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/module-context-with-instance-script/_config.js create mode 100644 test/runtime/samples/module-context-with-instance-script/main.html diff --git a/src/compile/nodes/shared/Expression.ts b/src/compile/nodes/shared/Expression.ts index 0d4dbd4960..852065d98d 100644 --- a/src/compile/nodes/shared/Expression.ts +++ b/src/compile/nodes/shared/Expression.ts @@ -240,7 +240,7 @@ export default class Expression { dependencies.add(name); component.template_references.add(name); } - } else if (!is_synthetic && !(component.hoistable_names.has(name) && template_scope.isTopLevel(name)) && !component.imported_declarations.has(name)) { + } else if (!is_synthetic && isContextual(component, template_scope, name)) { code.prependRight(node.start, key === 'key' && parent.shorthand ? `${name}: ctx.` : 'ctx.'); @@ -436,4 +436,17 @@ function get_function_name(node, parent) { } return 'func'; +} + +function isContextual(component: Component, scope: TemplateScope, name: string) { + // if it's a name below root scope, it's contextual + if (!scope.isTopLevel(name)) return true; + + // hoistables, module declarations, and imports are non-contextual + if (component.hoistable_names.has(name)) return false; + if (component.module_scope && component.module_scope.declarations.has(name)) return false; + if (component.imported_declarations.has(name)) return false; + + // assume contextual + return true; } \ No newline at end of file diff --git a/test/runtime/samples/module-context-with-instance-script/_config.js b/test/runtime/samples/module-context-with-instance-script/_config.js new file mode 100644 index 0000000000..902501fdd4 --- /dev/null +++ b/test/runtime/samples/module-context-with-instance-script/_config.js @@ -0,0 +1,3 @@ +export default { + html: `

(42)(99)

` +}; \ No newline at end of file diff --git a/test/runtime/samples/module-context-with-instance-script/main.html b/test/runtime/samples/module-context-with-instance-script/main.html new file mode 100644 index 0000000000..8769beaf3e --- /dev/null +++ b/test/runtime/samples/module-context-with-instance-script/main.html @@ -0,0 +1,9 @@ + + + + +

({foo})({bar})

\ No newline at end of file