diff options
author | 2021-04-09 14:09:13 -0400 | |
---|---|---|
committer | 2021-04-09 14:09:13 -0400 | |
commit | ad9c3b1d8dbf1c3aff75497271347ed36ea38a0b (patch) | |
tree | 8e0aed5ea1783df8322e1db589e84f9579152ba3 /test/astro-expr.test.js | |
parent | 084845f79d064626d5f5069ce7b945e3b44bdbd7 (diff) | |
download | astro-ad9c3b1d8dbf1c3aff75497271347ed36ea38a0b.tar.gz astro-ad9c3b1d8dbf1c3aff75497271347ed36ea38a0b.tar.zst astro-ad9c3b1d8dbf1c3aff75497271347ed36ea38a0b.zip |
Parse inner JSX as Astro (#67)
* Parse inner JSX as Astro
This completes the compiler changes, updating the parser so that it parses inner "JSX" as Astro. It does this by finding the start and end of HTML tags and feeds that back into the parser.
The result is a structure like this:
```
{
type: 'MustacheTag',
expression: [
{
type: 'Expression',
codeStart: 'colors.map(color => (',
codeEnd: '}}'
children: [ {
type: 'Fragment',
children: [ {
type: 'Element',
name: 'div'
} ]
} ]
}
]
}
```
There is a new Node type, `Expression`. Note that `MustacheTag` remains in the tree, all it contains is an Expression though. I could spend some time trying to remove it, there's just a few places that expect it to exist.
* Update import to the transform
* Transform prism components into expressions
Diffstat (limited to 'test/astro-expr.test.js')
-rw-r--r-- | test/astro-expr.test.js | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/test/astro-expr.test.js b/test/astro-expr.test.js index 9c73d719f..689c32ced 100644 --- a/test/astro-expr.test.js +++ b/test/astro-expr.test.js @@ -10,9 +10,47 @@ setup(Expressions, './fixtures/astro-expr'); Expressions('Can load page', async ({ runtime }) => { const result = await runtime.load('/'); - console.log(result); assert.equal(result.statusCode, 200); - console.log(result.contents); + + const $ = doc(result.contents); + + for(let col of ['red', 'yellow', 'blue']) { + assert.equal($('#' + col).length, 1); + } +}); + +Expressions('Ignores characters inside of strings', async ({ runtime }) => { + const result = await runtime.load('/strings'); + + assert.equal(result.statusCode, 200); + + const $ = doc(result.contents); + + for(let col of ['red', 'yellow', 'blue']) { + assert.equal($('#' + col).length, 1); + } +}); + +Expressions('Ignores characters inside of line comments', async ({ runtime }) => { + const result = await runtime.load('/line-comments'); + assert.equal(result.statusCode, 200); + + const $ = doc(result.contents); + + for(let col of ['red', 'yellow', 'blue']) { + assert.equal($('#' + col).length, 1); + } +}); + +Expressions('Ignores characters inside of multiline comments', async ({ runtime }) => { + const result = await runtime.load('/multiline-comments'); + assert.equal(result.statusCode, 200); + + const $ = doc(result.contents); + + for(let col of ['red', 'yellow', 'blue']) { + assert.equal($('#' + col).length, 1); + } }); Expressions.run(); |