You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/docs/04-compiler-and-api/01-svelte-compiler.md
+42-41Lines changed: 42 additions & 41 deletions
Original file line number
Diff line number
Diff line change
@@ -2,15 +2,15 @@
2
2
title: 'svelte/compiler'
3
3
---
4
4
5
-
Typically, you won't interact with the Svelte compiler directly, but will instead integrate it into your build system using a bundler plugin. The bundlerplugin that the Svelte team most recommends and invests in is[vite-plugin-svelte](https://github.com/sveltejs/vite-plugin-svelte). The [SvelteKit](https://kit.svelte.dev/)framework provides a setup leveraging `vite-plugin-svelte`to build applications as well as a [tool for packaging Svelte component libraries](https://kit.svelte.dev/docs/packaging). Svelte Society maintains a list of [other bundler plugins](https://sveltesociety.dev/tools/#bundling)for additional tools like Rollup and Webpack.
5
+
En général, vous n'interagirez pas directement avec le compilateur Svelte, mais vous l'intègrerez plutôt dans un processus de <spanclass="vo">[build](/docs/development#build)</span> à travers un <spanclass="vo">[plugin](/docs/development#plugin)</span> de <spanclass="vo">[bundler](/docs/web#bundler-packager)</span>. Le plugin que l'équipe Svelte recommande et avec lequel elle travaille est[vite-plugin-svelte](https://github.com/sveltejs/vite-plugin-svelte). Le <spanclass="vo">[framework](/docs/web#framework)</span> [SvelteKit](https://kit.svelte.dev/)fournit une configuration de `vite-plugin-svelte`qui permet de compiler des applications et de <spanclass="vo">[packager](/docs/web#bundler-packager)</span> des [librairies de composants Svelte](https://kit.svelte.dev/docs/packaging). Svelte Society maintient des [plugins](https://sveltesociety.dev/tools/#bundling)pour d'autres bundlers (notamment Rollup et Webpack).
6
6
7
-
Nonetheless, it's useful to understand how to use the compiler, since bundler plugins generally expose compiler options to you.
7
+
Néanmoins, il est utile de comprendre comment utiliser le compilateur, puisque les plugins exposent généralement des options.
8
8
9
9
## compile
10
10
11
11
> EXPORT_SNIPPET: svelte/compiler#compile
12
12
13
-
This is where the magic happens. `svelte.compile`takes your component source code, and turns it into a JavaScript module that exports a class.
13
+
C'est ici que la magie opère. `svelte.compile`convertit le code source des composants en module JavaScript qui exporte des classes.
14
14
15
15
```js
16
16
// @filename: ambient.d.ts
@@ -29,9 +29,9 @@ const result = compile(source, {
29
29
});
30
30
```
31
31
32
-
Refer to [CompileOptions](#types-compileoptions)for all the available options.
32
+
Référez-vous à la section [CompilerOptions](#types-compileoptions)pour voir les options disponibles.
33
33
34
-
The returned`result`object contains the code for your component, along with useful bits of metadata.
34
+
L'objet retourné`result`contient le code du composant, ainsi que des métadonnées utiles.
35
35
36
36
```ts
37
37
// @filename: ambient.d.ts
@@ -47,13 +47,13 @@ import { compile } from 'svelte/compiler';
Refer to [CompileResult](#types-compileresult)for a full description of the compile result.
50
+
Référez-vous à la section [CompilerResult](#types-compileresult)pour une description du résultat compilé.
51
51
52
52
## parse
53
53
54
54
> EXPORT_SNIPPET: svelte/compiler#parse
55
55
56
-
The `parse`function parses a component, returning only its abstract syntax tree. Unlike compiling with the `generate: false` option, this will not perform any validation or other analysis of the component beyond parsing it. Note that the returned AST is not considered public API, so breaking changes could occur at any point in time.
56
+
La méthode `parse`convertit un composant pour retourner son arbre syntaxique abstrait (<spanclass="vo">[AST](/docs/development#ast)</span>). Contrairement à la compilation avec l'option `generate: false`, aucune validation ni analyse n'est effectuée. Notez que l'AST n'est pas considéré comme une <spanclass="vo">[API](/docs/development#api)</span> publique ; des changements critiques pourraient survenir à n'importe quel moment.
A number of [official and community-maintained preprocessing plugins](https://sveltesociety.dev/tools#preprocessors)are available to allow you to use Svelte with tools like TypeScript, PostCSS, SCSS, and Less.
77
+
Un certain nombre de [plugins de pré-processeur maintenus par la communauté](https://sveltesociety.dev/tools#preprocessors)est disponible pour vous permettre d'utiliser Svelte avec des outils comme TypeScript, PostCSS, SCSS, et Less.
78
78
79
-
You can write your own preprocessor using the `svelte.preprocess`API.
79
+
Vous pouvez écrire votre propre pré-processeur en utilisant l'<spanclass="vo">[API](/docs/development#api)</span> `svelte.
80
80
81
-
The `preprocess`function provides convenient hooks for arbitrarily transforming component source code. For example, it can be used to convert a `<style lang="sass">`block into vanilla CSS.
81
+
La fonction `preprocess`fournit des <spanclass="vo">[framework](/docs/web#framework)</span> pour transformer le code source d'un composant selon vos besoins. Par exemple, elle peut convertir un bloc `<style lang="sass">`en css natif.
82
82
83
-
The first argument is the component source code. The second is an array of _preprocessors_ (or a single preprocessor, if you only have one), where a preprocessor is an object with a `name` which is required, and `markup`, `script`and`style` functions, each of which is optional.
83
+
Le premier argument est le code source du composant lui-même. Le second argument est un tableau de _pré-processeurs_ (ou éventuellement un seul pré-processeur si vous n'en avez qu'un). Un pré-processeur est un objet contenant trois fonctions : `markup`, `script`et`style`, toutes optionnelles.
84
84
85
-
The `markup`function receives the entire component source text, along with the component's `filename`if it was specified in the third argument.
85
+
La fonction `markup`reçoit en argument le <spanclass="vo">[markup](/docs/web#markup)</span> du composant, et le nom du composant `filename`s'il était spécifié comme troisième argument.
86
86
87
-
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.
87
+
Les fonctions `script`et`style`reçoivent le contenu des blocs`<script>`et`<style>`respectivement (`content`) ainsi que toute la source textuelle (`markup`) du composant. En plus du nom du fichier `filename`, elles reçoivent un objet contenant les attributs de l'élément.
88
88
89
-
Each `markup`, `script` or `style` function must return an object (or a Promise that resolves to an object) with a `code` property, representing the transformed source code. Optionally they can return an array of `dependencies` which represents files to watch for changes, and a `map` object which is a sourcemap mapping back the transformation to the original code. `script` and `style` preprocessors can optionally return a record of attributes which represent the updated attributes on the script/style tag.
89
+
Chaque fonction `markup`, `script` et `style` doit retourner un objet (ou une Promesse qui résout un objet) contenant un attribut `code`, représentant le code source transformé. Ces fonctions peuvent aussi renvoyer un tableau facultatif de dépendances `dependencies` qui représente les fichiers dont les changements sont à surveiller, ainsi qu'un objet `map` qui est une <spanclass="vo">[sourcemap](/docs/web#sourcemap)</span> renvoyant la transformation vers le code d'origine.
90
+
Les pré-processeurs `script` et `style` peuvent de manière optionnelle renvoyer un ensemble d'attributs qui représentent les attributs mis à jour sur les balises `<script>`/`<style>`.
90
91
91
-
> Preprocessor functions should return a `map`object whenever possible or else debugging becomes harder as stack traces can't link to the original code correctly.
92
+
> Les fonctions de <spanclass="vo">[preprocessing](/docs/web#preprocessing)</span> doivent également retourner un objet `map`en plus de `code` et `dependencies`, où `map` correspond à la <spanclass="vo">[sourcemap](/docs/web#sourcemap)</span> de la transformation.
If a `dependencies`array is returned, it will be included in the result object. This is used by packages like [vite-plugin-svelte](https://github.com/sveltejs/vite-plugin-svelte) and[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).
129
+
Si un tableau de dépendances `dependencies`est retourné, il sera inclus dans l'objet retourné. Ce tableau est utilisé par des librairies comme[rollup-plugin-svelte](https://github.com/sveltejs/rollup-plugin-svelte)pour surveiller les changements dans les fichiers, par exemple si un bloc`<style>`contient un import de type `@import`.
Multiple preprocessors can be used together. The output of the first becomes the input to the second. Within one preprocessor, `markup` runs first, then `script`and`style`.
203
+
Plusieurs pré-processeurs peuvent être utilisés ensemble. La sortie du premier devient l'argument du second. Les fonctions sont exécutées dans l'ordre suivant : `markup`, `script`puis`style`.
203
204
204
-
> In Svelte 3, all `markup`functions ran first, then all `script`and then all `style` preprocessors. This order was changed in Svelte 4.
205
+
> En Svelte 3, toutes les fonctions `markup`étaient exécutées en premier, puis toutes les fonctions `script`et enfin toutes les fonctions `style`. Cet ordre a été changé dans Svelte 4.
205
206
206
207
```js
207
208
// @errors: 2322
@@ -218,27 +219,27 @@ import { preprocess } from 'svelte/compiler';
The `walk`function provides a way to walk the abstract syntax trees generated by the parser, using the compiler's own built-in instance of [estree-walker](https://github.com/Rich-Harris/estree-walker).
254
+
La fonction `walk`fournit un un moyen de parcourir les arbres <spanclass="vo">[AST](/docs/development#ast)</span> générés par le <spanclass="vo">[parser](/docs/development#parser)</span>, en utilisant l'utilitaire [estree-walker](https://github.com/Rich-Harris/estree-walker) du compilateur.
254
255
255
-
The walker takes an abstract syntax tree to walk and an object with two optional methods: `enter`and`leave`. For each node, `enter`is called (if present). Then, unless `this.skip()`is called during `enter`, each of the children are traversed, and then`leave`is called on the node.
256
+
La fonction prend comme argument l'arbre <spanclass="vo">[AST](/docs/development#ast)</span> à traiter et un objet contenant 2 méthodes facultatives : `enter`et`leave`. `enter`est appelée pour chaque noeud (si la méthode est définie). Puis, à moins que `this.skip()`n'ait été appelée lors de l'exécution de `enter`, chaque enfant est également traversé. Enfin, la méthode`leave`est appelée pour le noeud actuel.
0 commit comments