From 76720ae4e6a8a34053c55a2c5e1de31866e6a615 Mon Sep 17 00:00:00 2001 From: Puru Vijay Date: Tue, 4 Apr 2023 00:54:33 +0530 Subject: [PATCH 1/4] CJS to ESM --- .../docs/04-compiler-and-api/01-svelte-compiler.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 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 0a47c0345f5d..186d1c0a564c 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, @@ -238,8 +238,8 @@ The `script` and `style` functions receive the contents of `