-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deconflict conextual action variable (#5839)
- Loading branch information
Showing
8 changed files
with
63 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Component from '../../Component'; | ||
import TemplateScope from './TemplateScope'; | ||
import { is_reserved_keyword } from '../../utils/reserved_keywords'; | ||
|
||
export default function is_contextual(component: Component, scope: TemplateScope, name: string) { | ||
if (is_reserved_keyword(name)) return true; | ||
|
||
// if it's a name below root scope, it's contextual | ||
if (!scope.is_top_level(name)) return true; | ||
|
||
const variable = component.var_lookup.get(name); | ||
|
||
// hoistables, module declarations, and imports are non-contextual | ||
if (!variable || variable.hoistable) return false; | ||
|
||
// assume contextual | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
test/runtime/samples/deconflict-contextual-action/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
let result; | ||
|
||
export default { | ||
before_test() { | ||
result = []; | ||
}, | ||
props: { | ||
collect: (str) => result.push(str) | ||
}, | ||
test({ assert }) { | ||
assert.deepEqual(result, ['each_action', 'import_action']); | ||
} | ||
}; |
17 changes: 17 additions & 0 deletions
17
test/runtime/samples/deconflict-contextual-action/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script> | ||
import action from './util.js'; | ||
export let collect; | ||
function each_action(_, fn) { | ||
fn('each_action'); | ||
} | ||
const array = [each_action]; | ||
</script> | ||
|
||
<div use:action={collect} /> | ||
|
||
<ul> | ||
{#each array as action} | ||
<div use:action={collect} /> | ||
{/each} | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function (_, fn) { | ||
fn('import_action'); | ||
} |