Merge pull request #2363 from jches/gh/2278

hoist all hoistable functions
pull/2364/head
Rich Harris 6 years ago committed by GitHub
commit 7d4a36af2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1023,7 +1023,7 @@ export default class Component {
};
for (const [name, node] of top_level_function_declarations) {
if (!checked.has(node) && is_hoistable(node)) {
if (is_hoistable(node)) {
const variable = this.var_lookup.get(name);
variable.hoistable = true;
hoistable_nodes.add(node);

@ -0,0 +1,7 @@
export default {
props: {
greeting: 'Good day'
},
html: '<h1>Good day, world</h1>'
}

@ -0,0 +1,15 @@
<script>
export let greeting = 'Hello'
let name = 'world';
// both functions, and `name` are hoistable, but hoistMe does not get hoisted
function hoistMeMaybe () {
return hoistMe(name) // comment out this line => hoistMe is hoisted
}
function hoistMe (name) {
return name
}
</script>
<h1>{greeting}, {hoistMeMaybe()}</h1>
Loading…
Cancel
Save