mirror of
https://github.com/sveltejs/svelte.git
synced 2024-11-30 00:46:29 +01:00
Pass full markup source to preprocessors (#6169)
This commit is contained in:
parent
a55295de8c
commit
08047c14b6
@ -199,11 +199,11 @@ result: {
|
|||||||
code: string,
|
code: string,
|
||||||
dependencies?: Array<string>
|
dependencies?: Array<string>
|
||||||
}>,
|
}>,
|
||||||
script?: (input: { content: string, attributes: Record<string, string>, filename: string }) => Promise<{
|
script?: (input: { content: string, markup: string, attributes: Record<string, string>, filename: string }) => Promise<{
|
||||||
code: string,
|
code: string,
|
||||||
dependencies?: Array<string>
|
dependencies?: Array<string>
|
||||||
}>,
|
}>,
|
||||||
style?: (input: { content: string, attributes: Record<string, string>, filename: string }) => Promise<{
|
style?: (input: { content: string, markup: string, attributes: Record<string, string>, filename: string }) => Promise<{
|
||||||
code: string,
|
code: string,
|
||||||
dependencies?: Array<string>
|
dependencies?: Array<string>
|
||||||
}>
|
}>
|
||||||
@ -242,7 +242,7 @@ const { code } = await svelte.preprocess(source, {
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
The `script` and `style` functions receive the contents of `<script>` and `<style>` elements respectively. In addition to `filename`, they get an object of the element's attributes.
|
The `script` and `style` functions receive the contents of `<script>` and `<style>` elements respectively (`content`) as well as the entire component source text (`markup`). In addition to `filename`, they get an object of the element's attributes.
|
||||||
|
|
||||||
If a `dependencies` array is returned, it will be included in the result object. This is used by packages like [rollup-plugin-svelte](https://github.com/sveltejs/rollup-plugin-svelte) to watch additional files for changes, in the case where your `<style>` tag has an `@import` (for example).
|
If a `dependencies` array is returned, it will be included in the result object. This is used by packages like [rollup-plugin-svelte](https://github.com/sveltejs/rollup-plugin-svelte) to watch additional files for changes, in the case where your `<style>` tag has an `@import` (for example).
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ async function process_tag(
|
|||||||
preprocessor: Preprocessor,
|
preprocessor: Preprocessor,
|
||||||
source: Source
|
source: Source
|
||||||
): Promise<SourceUpdate> {
|
): Promise<SourceUpdate> {
|
||||||
const { filename } = source;
|
const { filename, source: markup } = source;
|
||||||
const tag_regex =
|
const tag_regex =
|
||||||
tag_name === 'style'
|
tag_name === 'style'
|
||||||
? /<!--[^]*?-->|<style(\s[^]*?)?(?:>([^]*?)<\/style>|\/>)/gi
|
? /<!--[^]*?-->|<style(\s[^]*?)?(?:>([^]*?)<\/style>|\/>)/gi
|
||||||
@ -160,6 +160,7 @@ async function process_tag(
|
|||||||
const processed = await preprocessor({
|
const processed = await preprocessor({
|
||||||
content: content || '',
|
content: content || '',
|
||||||
attributes: parse_tag_attributes(attributes || ''),
|
attributes: parse_tag_attributes(attributes || ''),
|
||||||
|
markup,
|
||||||
filename
|
filename
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -20,8 +20,15 @@ export type MarkupPreprocessor = (options: {
|
|||||||
}) => Processed | Promise<Processed>;
|
}) => Processed | Promise<Processed>;
|
||||||
|
|
||||||
export type Preprocessor = (options: {
|
export type Preprocessor = (options: {
|
||||||
|
/**
|
||||||
|
* The script/style tag content
|
||||||
|
*/
|
||||||
content: string;
|
content: string;
|
||||||
attributes: Record<string, string | boolean>;
|
attributes: Record<string, string | boolean>;
|
||||||
|
/**
|
||||||
|
* The whole Svelte file content
|
||||||
|
*/
|
||||||
|
markup: string;
|
||||||
filename?: string;
|
filename?: string;
|
||||||
}) => Processed | Promise<Processed>;
|
}) => Processed | Promise<Processed>;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user