From beb3f653ee0b51552c3a914e64e693c2806da540 Mon Sep 17 00:00:00 2001 From: Puru Vijay <47742487+PuruVJ@users.noreply.github.com> Date: Tue, 4 Apr 2023 03:59:39 +0530 Subject: [PATCH] docs(site-2): CJS to ESM for code snippets (#8449) --- .../04-compiler-and-api/01-svelte-compiler.md | 49 ++++++++----------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/site/content/docs/04-compiler-and-api/01-svelte-compiler.md b/site/content/docs/04-compiler-and-api/01-svelte-compiler.md index 0a47c0345f..092ef6abbf 100644 --- a/site/content/docs/04-compiler-and-api/01-svelte-compiler.md +++ b/site/content/docs/04-compiler-and-api/01-svelte-compiler.md @@ -22,7 +22,7 @@ result: { This is where the magic happens. `svelte.compile` takes your component source code, and turns it into a JavaScript module that exports a class. ```js -const svelte = require('svelte/compiler'); +import svelte from 'svelte/compiler'; const result = svelte.compile(source, { // options @@ -160,7 +160,7 @@ ast: object = svelte.parse( 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. ```js -const svelte = require('svelte/compiler'); +import svelte from 'svelte/compiler'; const ast = svelte.parse(source, { filename: 'App.svelte' }); ``` @@ -208,8 +208,8 @@ The `markup` function receives the entire component source text, along with the > Preprocessor functions should additionally return a `map` object alongside `code` and `dependencies`, where `map` is a sourcemap representing the transformation. ```js -const svelte = require('svelte/compiler'); -const MagicString = require('magic-string'); +import svelte from 'svelte/compiler'; +import MagicString from 'magic-string'; const { code } = await svelte.preprocess( source, @@ -235,37 +235,27 @@ const { code } = await svelte.preprocess( The `script` and `style` functions receive the contents of `