-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Adds support for JSX elements: <Foo attr=val>{expr}</Foo> <Foo.Bar.Baz attr=val /> - The grammar uses nested_identifier for tags in the Foo.Bar.Baz form. It's the same symbol as what's used in namespaces: namespace Foo.Bar.Baz {} As such it ends up producing a bit of junk (unconnected cliques) but I don't know if it can be fixed w/o tree sitter queries supporting matching only if under a specified ancestor. - Unlike JavaScript, TypeScript requires variables to be declared. In JSX, <foo attr={x = 1}> {y = 2} </foo> is allowed if x, y are not in scope. They'll be created on first use. In TSX, this is disallowed which simplifies lexical_scope propogation compared to the JS TSG implementation.
- Loading branch information
1 parent
c09f746
commit 784376b
Showing
7 changed files
with
305 additions
and
14 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
39 changes: 39 additions & 0 deletions
39
languages/tree-sitter-stack-graphs-typescript/test/jsx/jsx_core.tsx
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,39 @@ | ||
// The core of JSX tests here verify the behavior of the following node types: | ||
// jsx_element | ||
// jsx_identifier | ||
// jsx_attribute | ||
// jsx_expression | ||
// jsx_opening_element | ||
// jsx_closing_element | ||
// There is no real way to avoid testing all of these at once, | ||
// and so we don't even try to. | ||
|
||
let x = 1; | ||
|
||
// Flow In | ||
|
||
const el = <foo bar={x}>{x}</foo>; | ||
// ^ defined: 11 | ||
// ^ defined: 11 | ||
|
||
const el2 = <x></x> | ||
// ^ defined: 11 | ||
// ^ defined: 11 | ||
|
||
let y = 0; | ||
let z = 2; | ||
|
||
const el = <foo bar={y = 1}> | ||
// ^ defined: 23 | ||
{z = 3} | ||
// ^ defined: 24 | ||
</foo>; | ||
|
||
/**/ y; | ||
// ^ defined: 23 | ||
|
||
/**/ z; | ||
// ^ defined: 24 | ||
|
||
/**/ x; | ||
// ^ defined: 11 |
12 changes: 12 additions & 0 deletions
12
languages/tree-sitter-stack-graphs-typescript/test/jsx/jsx_fragment.tsx
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,12 @@ | ||
let x = 1; | ||
|
||
// Flow Around | ||
|
||
const el = <></>; | ||
|
||
/**/ x; | ||
// ^ defined: 1 | ||
|
||
// Children | ||
(<foo><bar>{x}</bar></foo>); | ||
// ^ defined: 1 |
30 changes: 30 additions & 0 deletions
30
languages/tree-sitter-stack-graphs-typescript/test/jsx/jsx_namespace_name.tsx
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,30 @@ | ||
let x = 1; | ||
|
||
// Flow Around | ||
namespace noo.bar { | ||
export let baz = 1; | ||
} | ||
|
||
const el = <noo.bar.baz></noo.bar.baz>; | ||
// ^ defined: 4 | ||
// ^ defined: 4 | ||
// ^ defined: 5 | ||
// ^ defined: 4 | ||
// ^ defined: 4 | ||
// ^ defined: 5 | ||
|
||
/**/ x; | ||
// ^ defined: 1 | ||
|
||
// Flow In | ||
|
||
let foo = { | ||
bar: { | ||
baz: 1 | ||
} | ||
}; | ||
|
||
const el2 = <foo.bar.baz />; | ||
// ^ defined: 21 | ||
// ^ defined: 22 | ||
// ^ defined: 23 |
37 changes: 37 additions & 0 deletions
37
languages/tree-sitter-stack-graphs-typescript/test/jsx/jsx_self_closing_element.tsx
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,37 @@ | ||
// The core of JSX tests here verify the behavior of the following node types: | ||
// jsx_element | ||
// jsx_identifier | ||
// jsx_attribute | ||
// jsx_expression | ||
// jsx_opening_element | ||
// jsx_closing_element | ||
// There is no real way to avoid testing all of these at once, | ||
// and so we don't even try to. | ||
|
||
let x = 1; | ||
|
||
// Flow In | ||
|
||
const el = <foo bar={x} />; | ||
// ^ defined: 11 | ||
|
||
const el2 = <x /> | ||
// ^ defined: 11 | ||
|
||
// Flow Out | ||
|
||
let y = 2; | ||
|
||
const el = <foo bar={y = 1} />; | ||
// ^ defined: 23 | ||
|
||
// Flow Across | ||
|
||
const el = <foo bar={y = 1} | ||
baz={y} />; | ||
// ^ defined: 23 | ||
|
||
// Flow Around | ||
|
||
/**/ x; | ||
// ^ defined: 11 |
8 changes: 8 additions & 0 deletions
8
languages/tree-sitter-stack-graphs-typescript/test/jsx/jsx_text.tsx
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,8 @@ | ||
let x = 1; | ||
|
||
// Flow Around | ||
|
||
const el = <foo>bar</foo>; | ||
|
||
/**/ x; | ||
// ^ defined: 1 |