improved scope rules
This commit is contained in:
1 parent
ca01dd5f95
commit
aceae012fa
7 files changed
+15412
-15051
No files matched your search
@@ -222,7 +222,11 @@ captured through its field instead (`(filter name: (identifier))`, `(custom_tag
|
|||||||
|
|
||||||
`queries/libraries.scm` is not a query editors run themselves; it is data for a linter, and every tag or
|
`queries/libraries.scm` is not a query editors run themselves; it is data for a linter, and every tag or
|
||||||
filter added from a library belongs in it. `queries/locals.scm` relies on the `variable:` field to tell a
|
filter added from a library belongs in it. `queries/locals.scm` relies on the `variable:` field to tell a
|
||||||
binding from a reference — another reason to keep `asVariable` uniform.
|
binding from a reference — another reason to keep `asVariable` uniform. `{% blocktranslate %}`'s `asvar`
|
||||||
|
target carries an `asvar:` field instead, because it is written inside the tag but assigned outside it:
|
||||||
|
the scope on `blocktranslate_group` confines the `with` and `count` bindings, and would swallow `asvar`
|
||||||
|
too if it were spelled the same way. Defining it in the surrounding scope is left to the tool, since a
|
||||||
|
locals query cannot let a definition out of the scope that contains it.
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -542,7 +542,10 @@ const django = grammar({
|
|||||||
seq(part("with"), $._tag_kwargs),
|
seq(part("with"), $._tag_kwargs),
|
||||||
part("context", $.filtered_value),
|
part("context", $.filtered_value),
|
||||||
part("trimmed"),
|
part("trimmed"),
|
||||||
part("asvar", field("variable", $.identifier)),
|
// asvar names where the rendered text is stored, which is read
|
||||||
|
// after the block rather than inside it, so it is not a binding of
|
||||||
|
// the block the way "with" and "count" are
|
||||||
|
part("asvar", field("asvar", $.identifier)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
_translate_count: ($) =>
|
_translate_count: ($) =>
|
||||||
|
|||||||
@@ -3,5 +3,17 @@
|
|||||||
|
|
||||||
variable: (identifier) @local.definition
|
variable: (identifier) @local.definition
|
||||||
|
|
||||||
|
; The tags whose Node pushes a context, so that what they bind is not visible
|
||||||
|
; after them. Verified by rendering: "{% block b %}{% now "Y" as n %}{% endblock %}{{ n }}"
|
||||||
|
; is empty, while the same around an "{% if %}" is not, because if does not push.
|
||||||
(with_clause) @local.scope
|
(with_clause) @local.scope
|
||||||
(for_clause) @local.scope
|
(for_clause) @local.scope
|
||||||
|
(block_clause) @local.scope
|
||||||
|
(partialdef_clause) @local.scope
|
||||||
|
|
||||||
|
; blocktranslate pushes a context for its "with" and "count" bindings. Its
|
||||||
|
; asvar target is not one of them: it is written in the same tag but assigned
|
||||||
|
; outside it, and carries an "asvar" field rather than "variable" so that this
|
||||||
|
; scope does not swallow it. A tool that wants it must define it in the scope
|
||||||
|
; around the block, which a locals query has no way to say.
|
||||||
|
(blocktranslate_group) @local.scope
|
||||||
+1
-1
@@ -2061,7 +2061,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "FIELD",
|
"type": "FIELD",
|
||||||
"name": "variable",
|
"name": "asvar",
|
||||||
"content": {
|
"content": {
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "identifier"
|
"name": "identifier"
|
||||||
|
|||||||
@@ -330,6 +330,16 @@
|
|||||||
"type": "blocktranslate_group",
|
"type": "blocktranslate_group",
|
||||||
"named": true,
|
"named": true,
|
||||||
"fields": {
|
"fields": {
|
||||||
|
"asvar": {
|
||||||
|
"multiple": true,
|
||||||
|
"required": false,
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "identifier",
|
||||||
|
"named": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"tag": {
|
"tag": {
|
||||||
"multiple": true,
|
"multiple": true,
|
||||||
"required": true,
|
"required": true,
|
||||||
|
|||||||
+15377
-15045
File diff suppressed because it is too large.
Load diff
@@ -165,7 +165,7 @@ Blocktrans With Asvar
|
|||||||
(template
|
(template
|
||||||
(content)
|
(content)
|
||||||
(blocktranslate_group
|
(blocktranslate_group
|
||||||
variable: (identifier)
|
asvar: (identifier)
|
||||||
(content))
|
(content))
|
||||||
(content))
|
(content))
|
||||||
|
|
||||||
@@ -214,7 +214,7 @@ Blocktrans With Every Option
|
|||||||
(value
|
(value
|
||||||
(literal
|
(literal
|
||||||
(string))))
|
(string))))
|
||||||
variable: (identifier)
|
asvar: (identifier)
|
||||||
(content)
|
(content)
|
||||||
(content))
|
(content))
|
||||||
(content))
|
(content))
|
||||||
@@ -230,7 +230,7 @@ Blocktrans With Its Options Reordered
|
|||||||
(template
|
(template
|
||||||
(content)
|
(content)
|
||||||
(blocktranslate_group
|
(blocktranslate_group
|
||||||
variable: (identifier)
|
asvar: (identifier)
|
||||||
(content))
|
(content))
|
||||||
(content))
|
(content))
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user