mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
* fix(#2753): unescape `define:vars` * test: add directives suite * chore: update lockfile
This commit is contained in:
parent
7b18d4c226
commit
5f55af9cce
5 changed files with 48 additions and 2 deletions
|
@ -391,7 +391,7 @@ export function defineStyleVars(selector: string, vars: Record<any, any>) {
|
|||
for (const [key, value] of Object.entries(vars)) {
|
||||
output += ` --${key}: ${value};\n`;
|
||||
}
|
||||
return `${selector} {${output}}`;
|
||||
return unescapeHTML(`${selector} {${output}}`);
|
||||
}
|
||||
|
||||
// Adds variables to an inline script.
|
||||
|
@ -400,7 +400,7 @@ export function defineScriptVars(vars: Record<any, any>) {
|
|||
for (const [key, value] of Object.entries(vars)) {
|
||||
output += `let ${key} = ${JSON.stringify(value)};\n`;
|
||||
}
|
||||
return output;
|
||||
return unescapeHTML(output);
|
||||
}
|
||||
|
||||
// Renders an endpoint request to completion, returning the body.
|
||||
|
|
20
packages/astro/test/astro-directives.test.js
Normal file
20
packages/astro/test/astro-directives.test.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
import { expect } from 'chai';
|
||||
import cheerio from 'cheerio';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
|
||||
describe('Directives', async () => {
|
||||
let fixture;
|
||||
|
||||
before(async () => {
|
||||
fixture = await loadFixture({ projectRoot: './fixtures/astro-directives/' });
|
||||
await fixture.build();
|
||||
});
|
||||
|
||||
it('Passes define:vars to script elements', async () => {
|
||||
const html = await fixture.readFile('/define-vars/index.html');
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
expect($('script#inline')).to.have.lengthOf(1);
|
||||
expect($('script#inline').toString()).to.include('let foo = "bar"');
|
||||
});
|
||||
});
|
8
packages/astro/test/fixtures/astro-directives/package.json
vendored
Normal file
8
packages/astro/test/fixtures/astro-directives/package.json
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"name": "@astrojs/test-astro-directives",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"astro": "workspace:*"
|
||||
}
|
||||
}
|
12
packages/astro/test/fixtures/astro-directives/src/pages/define-vars.astro
vendored
Normal file
12
packages/astro/test/fixtures/astro-directives/src/pages/define-vars.astro
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
let foo = 'bar'
|
||||
---
|
||||
|
||||
<html>
|
||||
<head></head>
|
||||
<body>
|
||||
<script id="inline" define:vars={{ foo }}>
|
||||
console.log(foo);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -582,6 +582,12 @@ importers:
|
|||
dependencies:
|
||||
astro: link:../../..
|
||||
|
||||
packages/astro/test/fixtures/astro-directives:
|
||||
specifiers:
|
||||
astro: workspace:*
|
||||
dependencies:
|
||||
astro: link:../../..
|
||||
|
||||
packages/astro/test/fixtures/astro-doctype:
|
||||
specifiers:
|
||||
astro: workspace:*
|
||||
|
|
Loading…
Reference in a new issue