From b8453076989aac5175f7322f468338b60293eaeb Mon Sep 17 00:00:00 2001
From: Bjorn Lu <34116392+bluwy@users.noreply.github.com>
Date: Thu, 23 Sep 2021 01:21:40 +0800
Subject: [PATCH 001/636] [fix] handle preprocess with empty sourcemaps (#6757)
---
src/compiler/preprocess/index.ts | 11 +++++++----
test/preprocess/samples/empty-sourcemap/_config.js | 7 +++++++
test/preprocess/samples/empty-sourcemap/input.svelte | 7 +++++++
test/preprocess/samples/empty-sourcemap/output.svelte | 7 +++++++
4 files changed, 28 insertions(+), 4 deletions(-)
create mode 100644 test/preprocess/samples/empty-sourcemap/_config.js
create mode 100644 test/preprocess/samples/empty-sourcemap/input.svelte
create mode 100644 test/preprocess/samples/empty-sourcemap/output.svelte
diff --git a/src/compiler/preprocess/index.ts b/src/compiler/preprocess/index.ts
index 10771603d7..c2a8e3b7d2 100644
--- a/src/compiler/preprocess/index.ts
+++ b/src/compiler/preprocess/index.ts
@@ -79,10 +79,13 @@ function processed_content_to_code(processed: Processed, location: SourceLocatio
if (processed.map) {
decoded_map = decode_map(processed);
- // offset only segments pointing at original component source
- const source_index = decoded_map.sources.indexOf(file_basename);
- if (source_index !== -1) {
- sourcemap_add_offset(decoded_map, location, source_index);
+ // decoded map may not have sources for empty maps like `{ mappings: '' }`
+ if (decoded_map.sources) {
+ // offset only segments pointing at original component source
+ const source_index = decoded_map.sources.indexOf(file_basename);
+ if (source_index !== -1) {
+ sourcemap_add_offset(decoded_map, location, source_index);
+ }
}
}
diff --git a/test/preprocess/samples/empty-sourcemap/_config.js b/test/preprocess/samples/empty-sourcemap/_config.js
new file mode 100644
index 0000000000..941661ce01
--- /dev/null
+++ b/test/preprocess/samples/empty-sourcemap/_config.js
@@ -0,0 +1,7 @@
+export default {
+ preprocess: {
+ style: ({ content }) => {
+ return { code: content, map: { mappings: '' } };
+ }
+ }
+};
diff --git a/test/preprocess/samples/empty-sourcemap/input.svelte b/test/preprocess/samples/empty-sourcemap/input.svelte
new file mode 100644
index 0000000000..d2380c00cb
--- /dev/null
+++ b/test/preprocess/samples/empty-sourcemap/input.svelte
@@ -0,0 +1,7 @@
+
bar
+
+
\ No newline at end of file
diff --git a/test/preprocess/samples/empty-sourcemap/output.svelte b/test/preprocess/samples/empty-sourcemap/output.svelte
new file mode 100644
index 0000000000..d2380c00cb
--- /dev/null
+++ b/test/preprocess/samples/empty-sourcemap/output.svelte
@@ -0,0 +1,7 @@
+
-{/if}
\ No newline at end of file
+{/if}
diff --git a/test/runtime/index.ts b/test/runtime/index.ts
index ff6d1039d3..e777196ae2 100644
--- a/test/runtime/index.ts
+++ b/test/runtime/index.ts
@@ -25,12 +25,13 @@ let compile = null;
const sveltePath = process.cwd().split('\\').join('/');
let unhandled_rejection = false;
-process.on('unhandledRejection', err => {
+function unhandledRejection_handler(err) {
unhandled_rejection = err;
-});
+}
describe('runtime', () => {
before(() => {
+ process.on('unhandledRejection', unhandledRejection_handler);
svelte = loadSvelte(false);
svelte$ = loadSvelte(true);
@@ -46,6 +47,7 @@ describe('runtime', () => {
return setupHtmlEqual();
});
+ after(() => process.removeListener('unhandledRejection', unhandledRejection_handler));
const failed = new Set();
From 33deaaa4c4db7cb83384dc1266ca2a35e488290c Mon Sep 17 00:00:00 2001
From: Conduitry
Date: Thu, 30 Sep 2021 08:27:19 -0400
Subject: [PATCH 014/636] -> v3.43.1
---
CHANGELOG.md | 4 ++++
package-lock.json | 2 +-
package.json | 2 +-
3 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 54a678accb..59bdc33c5b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# Svelte changelog
+## 3.43.1
+
+* Prevent a rejecting promise used in `{#await}` during SSR from appearing as an unhandled rejection ([#6789](https://github.com/sveltejs/svelte/issues/6789))
+
## 3.43.0
* Use export map to expose no-op versions of lifecycle functions for SSR ([#6743](https://github.com/sveltejs/svelte/pull/6743))
diff --git a/package-lock.json b/package-lock.json
index 4bc3337e32..71742ebeed 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "svelte",
- "version": "3.43.0",
+ "version": "3.43.1",
"lockfileVersion": 2,
"requires": true,
"packages": {
diff --git a/package.json b/package.json
index e6991fd5c0..0736178244 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "svelte",
- "version": "3.43.0",
+ "version": "3.43.1",
"description": "Cybernetically enhanced web apps",
"module": "index.mjs",
"main": "index",
From 54ba76c1f050f33e47ec01f1f86d4875d2794896 Mon Sep 17 00:00:00 2001
From: Daniel Sandoval
Date: Thu, 30 Sep 2021 08:16:03 -0700
Subject: [PATCH 015/636] [docs] "What's new in Svelte" October newsletter
(#6774)
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Co-authored-by: Bjorn Lu <34116392+bluwy@users.noreply.github.com>
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
---
...-10-01-whats-new-in-svelte-october-2021.md | 99 +++++++++++++++++++
1 file changed, 99 insertions(+)
create mode 100644 site/content/blog/2021-10-01-whats-new-in-svelte-october-2021.md
diff --git a/site/content/blog/2021-10-01-whats-new-in-svelte-october-2021.md b/site/content/blog/2021-10-01-whats-new-in-svelte-october-2021.md
new file mode 100644
index 0000000000..78fa05dbe2
--- /dev/null
+++ b/site/content/blog/2021-10-01-whats-new-in-svelte-october-2021.md
@@ -0,0 +1,99 @@
+---
+title: What's new in Svelte: October 2021
+description: A whole year of "What's new in Svelte"
+author: Daniel Sandoval
+authorURL: https://desandoval.net
+---
+
+Hey y'all 👋 It's been 1 year since "What's new in Svelte" started being cross-posted to the Svelte blog. I wanted to take this moment at the top to thank all of you for reading and for all the contributors every month. From the maintainers to everyone who posts their work in the Discord and Reddit, it's amazing to witness all the effort that goes into making the Svelte community great.
+
+Keep up the good work, everyone! Now, let's dive into this month's news...
+
+## New around Svelte
+
+- New additions to Svelte's export map now expose no-op versions of lifecycle functions for SSR (Svelte **3.43.0**)
+- Custom components with a `src` attribute no longer break `svelte-native` builds (Svelte **3.42.4**)
+- Svelte plugin users without [the TypeScript plugin](https://www.npmjs.com/package/typescript-svelte-plugin) enabled will now be prompted to enable it. It enhances TypeScript and JavaScript files with additional intellisense to interact with Svelte files. [Please leave feedback](https://github.com/sveltejs/language-tools/issues/580) if you are using it (Svelte extensions **105.4.0**)
+- Event modifiers have been added to intellisense as autocomplete and hover info (Svelte extensions **105.4.0**)
+- TypeScript users no longer have to strictly separate type imports and value imports when using Svelte version 3.39 or higher and `svelte-preprocess` version 4.9.5 or higher. This means you can now write `import { MyInterface, myValue } from './somewhere'` instead of `import type { MyInterface } from './somewhere'; import { myValue } from './somewhere'`. Huge thanks to community member [@SomaticIT](https://github.com/SomaticIT) who mainly implemented this!
+
+For a full list of features and bug fixes, check out the [Svelte changelog](https://github.com/sveltejs/svelte/blob/master/CHANGELOG.md).
+
+## SvelteKit Updates
+
+Nearly 100 PRs committed again this past month, but there's still lots to do and Svelte maintainers are [looking for help getting SvelteKit to 1.0](https://github.com/sveltejs/kit/issues/2100). Antony said it well in a [recent comment](https://github.com/sveltejs/kit/issues/2100#issuecomment-895446285) on the issue:
+
+> If you think you are too n00b to contribute (you're not), then add tests, or write tests for the feature you want to add, before you add it! Start small, and learn the codebase that way.
+
+If you'd like to help, please consider working on any of the [1.0 milestone issues labeled with "help wanted"](https://github.com/sveltejs/kit/issues?q=is%3Aopen+is%3Aissue+milestone%3A1.0+label%3A%22help+wanted%22).
+
+Notable SvelteKit improvements this month include...
+
+- Service workers are now allowed to access files using the `$lib` alias ([#2326](https://github.com/sveltejs/kit/pull/2326))
+- Svelte libraries should now work out-of-the-box without any Vite configuration ([#2343](https://github.com/sveltejs/kit/pull/2343))
+- Improvements to package exports field ([#2345](https://github.com/sveltejs/kit/pull/2345) and [#2327](https://github.com/sveltejs/kit/pull/2327))
+- [breaking] The `prerender.pages` config option has been renamed to `prerender.entries` ([#2380](https://github.com/sveltejs/kit/pull/2380))
+- A new generic argument has beend added to allow typing Body from hooks ([#2413](https://github.com/sveltejs/kit/pull/2413))
+- The `svelte` field will be added to package.json when running the package command ([#2431](https://github.com/sveltejs/kit/pull/2431))
+- [breaking] The `context` parameter of the load function was renamed to `stuff` ([#2439](https://github.com/sveltejs/kit/pull/2439))
+- Added an `entryPoint` option for building a custom server with `adapter-node` ([#2414](https://github.com/sveltejs/kit/pull/2414))
+- `vite-plugin-svelte` improved support for [useVitePreprocess](https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/config.md#usevitepreprocess), which uses Vite to automatically preprocess TypeScript, PostCSS, Scss, etc in Svelte components ([#173](https://github.com/sveltejs/vite-plugin-svelte/pull/173))
+
+To see all updates to SvelteKit, check out the [SvelteKit changelog](https://github.com/sveltejs/kit/blob/master/packages/kit/CHANGELOG.md).
+
+
+---
+
+## Community Showcase
+
+**Apps & Sites**
+- [radiofrance](https://www.radiofrance.fr/) just migrated their website to SvelteKit
+- [FLAYKS](https://flayks.com/) is the portfolio site for Félix Péault made with SvelteKit, Sanity, and Anime.js
+- [hirehive](https://www.hirehive.com/) is a candidate and job tracking site
+- [Microsocial](https://microsocial.xyz/) is an experimental Peer-to-Peer Social Platform
+- [Dylan Ipsum](https://www.dylanlyrics.app/) is a random text generator to replace lorem ipsum with Bob Dylan lyrics
+- [Chip8 Svelte](https://github.com/mikeyhogarth/chip8-svelte) is a CHIP-8 emulator frontend, built on top of CHIP8 Typescript
+
+**Looking for a Svelte project to work on? Interested in helping make Svelte's presence on the web better?** Check out [the list of open issues](https://github.com/svelte-society/sveltesociety-2021/issues) if you'd like to contribute to the Svelte Society rewrite in SvelteKit.
+
+**Podcasts Featuring Svelte**
+- [Syntax Podast: From React to SvelteKit](https://podcasts.apple.com/us/podcast/from-react-to-sveltekit/id1253186678?i=1000536276106) Scott talks with Wes about moving Level Up Tutorials from React to SvelteKit — why he did it, how, benefits, things to watch out for, and more!
+- [Web Rush Podcast: Svelte Tools and Svelte Society](https://www.webrush.io/episodes/episode-150-svelte-tools-and-svelte-society) Kevin Åberg Kultalahti talks about what Svelte Society is, what he's excited about with Svelte, how important documentation is to any product, and much _much_ more
+- [Svelte: The Compiled Future of Front End](https://www.arahansen.com/the-compiled-future-of-front-end/) details the history of component-based frontends and how a compiler changes everything
+- [Svelte Radio: Contributing to Svelte with Martin 'Grygrflzr' Krisnanto Putra](https://share.transistor.fm/s/10aa305c) Grygrflzr shares his journey to becoming a maintainer and his views on React, Vite and a host of other things
+- [Svelte Radio: Routify 3 with Jake and Willow](https://share.transistor.fm/s/10aa305c) the Svelte Radio crew sits down with the maintainers of Routify and discusses the just-released Routify 3
+- [JS Party: 1Password](https://twitter.com/geoffrich_/status/1441816829853253640?s=20) mentioned on the latest episode of The Changelog's JS Party that they use Svelte to power their in-page suggestions
+
+**Educational Content**
+- [How I built a blog with Svelte and SvelteKit](https://fantinel.dev/blog-development-sveltekit/) is an introduction to Svelte, SvelteKit and Progressive Enhancement with code examples
+- [I built a decentralized chat dapp](https://www.youtube.com/watch?v=J5x3OMXjgMc) is a tutorial on how to use popular web3 technologies like GUN to build a decentralized web app (dapp)
+- [Writing a Svelte Store with TypeScript](https://javascript.plainenglish.io/writing-a-svelte-store-with-typescript-22fa1c901a4) is a deep dive into writing Svelte stores with TypeScript
+- [How Svelte scopes component styles](https://geoffrich.net/posts/svelte-scoped-styles/) explains scoping using classes and more complex CSS specifiers
+- [SvelteKit Hooks](https://www.youtube.com/watch?v=RarufLoEL08) shows how to use hooks.js in Sveltekit.. When you're done, check out [Part 2](https://www.youtube.com/watch?v=RmIBG3G0-VY)
+- [An early look at SvelteKit](https://www.infoworld.com/article/3630395/an-early-look-at-sveltekit.html) is a post from Infoworld walking through the features and onboarding of SvelteKit
+
+**Libraries, Tools & Components**
+- [sveltekit-netlify-cms](https://github.com/buhrmi/sveltekit-netlify-cms) is a SvelteKit skeleton app configured for use with Netlify CMS
+- [SvelteFireTS](https://github.com/jacobbowdoin/sveltefirets) is a SvelteKit + Typescript + Firebase library inspired by Fireship.io
+- [stores-x](https://github.com/Anyass3/stores-x) lets you use Svelte stores just like vueX
+- [sveltekit-snippets](https://github.com/stordahl/sveltekit-snippets) is a VSCode extension that provides snippets for common patterns in SvelteKit & Vanilla Svelte
+- [svelte-xactor](https://github.com/wobsoriano/svelte-xactor) is a middleware that allows you to easily convert your xactor machines into a global store that implements the store contract
+- [vite-plugin-pages-svelte](https://github.com/aldy505/vite-plugin-pages-svelte) is a vite plugin for automatic filesystem-based routing
+- [sveltio](https://www.npmjs.com/package/sveltio) is a Svelte wrapper for valtio - a proxy-state library
+- [svelte-transition-classes](https://github.com/rmarscher/svelte-transition-classes) is a custom Svelte transition for adding and swapping CSS classes
+- [Svelte-Boring-Avatars](https://github.com/paolotiu/svelte-boring-avatars) is Svelte port of the popular [Boring Avatars](https://github.com/boringdesigners/boring-avatars) React project
+- [Svelte DataTables](https://github.com/homescriptone/svelte-datatables) brings DataTable, a popular JavaScript library allowing you to easily display your data in a user-friendly table, into your Svelte project.
+- [focus-svelte](https://github.com/chanced/focus-svelte) is a focus trap for Svelte with zero dependencies
+- [filedrop-svelte](https://github.com/chanced/filedrop-svelte) is a file dropzone action & component for Svelte
+
+
+Check out the community site [sveltesociety.dev](https://sveltesociety.dev/templates/) for more templates, adders and adapters from across the Svelte ecosystem.
+
+
+## Before you go, answer the call for speakers!
+
+Svelte Summit Fall 2021 (happening 20 November 2021) is looking for speakers. Submit your talk propsoal before 30 October... all are welcome to present and attend.
+
+### More info on the [sessionize site](https://sessionize.com/svelte-summit-fall-2021/)
+
+Can't wait for the summit? Join us on [Reddit](https://www.reddit.com/r/sveltejs/) or [Discord](https://discord.com/invite/yy75DKs)!
From 0d4ad364bea034cffc0326b321395b5231cd8477 Mon Sep 17 00:00:00 2001
From: Ben McCann <322311+benmccann@users.noreply.github.com>
Date: Thu, 30 Sep 2021 08:22:30 -0700
Subject: [PATCH 016/636] Add OpenCollective donors to site (#6793)
---
.gitignore | 2 +
site/scripts/get_donors.js | 63 +++++++++++++++++++++++
site/scripts/update.js | 1 +
site/src/routes/_components/Donors.svelte | 27 ++++++++++
site/src/routes/index.svelte | 13 ++++-
5 files changed, 104 insertions(+), 2 deletions(-)
create mode 100644 site/scripts/get_donors.js
create mode 100644 site/src/routes/_components/Donors.svelte
diff --git a/.gitignore b/.gitignore
index 911ff19cab..38a69c939b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -30,7 +30,9 @@ _output
/site/.sessions
/site/static/svelte-app.json
/site/static/contributors.jpg
+/site/static/donors.jpg
/site/static/workers
/site/scripts/svelte-app
/site/scripts/community
/site/src/routes/_contributors.js
+/site/src/routes/_donors.js
diff --git a/site/scripts/get_donors.js b/site/scripts/get_donors.js
new file mode 100644
index 0000000000..9e26391195
--- /dev/null
+++ b/site/scripts/get_donors.js
@@ -0,0 +1,63 @@
+import 'dotenv/config';
+import fs from 'fs';
+import fetch from 'node-fetch';
+import Jimp from 'jimp';
+import { dirname } from 'path';
+import { fileURLToPath } from 'url';
+
+
+const force = process.env.FORCE_UPDATE === 'true';
+
+const __dirname = dirname(fileURLToPath(import.meta.url));
+process.chdir(__dirname);
+
+const outputFile = `../src/routes/_donors.js`;
+if (!force && fs.existsSync(outputFile)) {
+ console.info(`[update/donors] ${outputFile} exists. Skipping`);
+ process.exit(0);
+}
+
+const SIZE = 64;
+
+async function main() {
+ const res = await fetch('https://opencollective.com/svelte/members/all.json');
+ const donors = await res.json();
+
+ const unique = new Map();
+ donors.forEach(d => unique.set(d.profile, d));
+
+ let backers = [...unique.values()]
+ .filter(({ role }) => role === 'BACKER')
+ .sort((a, b) => b.totalAmountDonated - a.totalAmountDonated);
+
+ const included = [];
+ for (let i = 0; i < backers.length; i += 1) {
+ const backer = backers[i];
+ console.log(`${i} / ${backers.length}: ${backer.name}`);
+
+ try {
+ const image_data = await fetch(backer.image);
+ const buffer = await image_data.arrayBuffer();
+ const image = await Jimp.read(buffer);
+ image.resize(SIZE, SIZE);
+ included.push({ backer, image });
+ } catch( err) {
+ console.log(`Skipping ${backer.name}: no image data`);
+ }
+ }
+
+ const sprite = new Jimp(SIZE * included.length, SIZE);
+ for (let i = 0; i < included.length; i += 1) {
+ sprite.composite(included[i].image, i * SIZE, 0);
+ }
+
+ await sprite.quality(80).write(`../static/donors.jpg`);
+ // TODO: Optimizing the static/donors.jpg image should probably get automated as well
+ console.log('remember to additionally optimize the resulting /static/donors.jpg image file via e.g. https://squoosh.app ');
+
+ const str = `[\n\t${included.map(a => `${JSON.stringify(a.backer.name)}`).join(',\n\t')}\n]`;
+
+ fs.writeFileSync(outputFile, `export default ${str};`);
+}
+
+main();
diff --git a/site/scripts/update.js b/site/scripts/update.js
index 1e8789e67c..724c0d1be8 100644
--- a/site/scripts/update.js
+++ b/site/scripts/update.js
@@ -4,5 +4,6 @@ sh.env['FORCE_UPDATE'] = process.argv.includes('--force=true');
Promise.all([
sh.exec('node ./scripts/get_contributors.js'),
+ sh.exec('node ./scripts/get_donors.js'),
sh.exec('node ./scripts/update_template.js')
]);
diff --git a/site/src/routes/_components/Donors.svelte b/site/src/routes/_components/Donors.svelte
new file mode 100644
index 0000000000..dc1f7ffcc8
--- /dev/null
+++ b/site/src/routes/_components/Donors.svelte
@@ -0,0 +1,27 @@
+
+
+
+
+{#each donors as donor, i}
+
+ {donor}
+
+{/each}
diff --git a/site/src/routes/index.svelte b/site/src/routes/index.svelte
index 3c84d6ea15..4290c99778 100644
--- a/site/src/routes/index.svelte
+++ b/site/src/routes/index.svelte
@@ -1,6 +1,7 @@
+
+
Hello {name}!
\ No newline at end of file
From 3f11232d241bc721eb084229da720b6079cdee6c Mon Sep 17 00:00:00 2001
From: Conduitry
Date: Tue, 12 Oct 2021 16:16:44 -0400
Subject: [PATCH 029/636] -> v3.43.2
---
CHANGELOG.md | 4 ++++
package-lock.json | 4 ++--
package.json | 2 +-
3 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 59bdc33c5b..883fdcd56f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# Svelte changelog
+## 3.43.2
+
+* Fix regression where user-specified `import`s were not rewritten according to the `sveltePath` option ([#6834](https://github.com/sveltejs/svelte/issues/6834))
+
## 3.43.1
* Prevent a rejecting promise used in `{#await}` during SSR from appearing as an unhandled rejection ([#6789](https://github.com/sveltejs/svelte/issues/6789))
diff --git a/package-lock.json b/package-lock.json
index 872f3c61ea..4ea2ce35bc 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "svelte",
- "version": "3.43.1",
+ "version": "3.43.2",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "svelte",
- "version": "3.43.1",
+ "version": "3.43.2",
"license": "MIT",
"devDependencies": {
"@ampproject/remapping": "^0.3.0",
diff --git a/package.json b/package.json
index 5b67d2c541..511ca60e05 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "svelte",
- "version": "3.43.1",
+ "version": "3.43.2",
"description": "Cybernetically enhanced web apps",
"module": "index.mjs",
"main": "index",
From be1eff0305236fbf0c103ba94638d8d6c428a77b Mon Sep 17 00:00:00 2001
From: Bjorn Lu <34116392+bluwy@users.noreply.github.com>
Date: Mon, 18 Oct 2021 01:04:35 +0800
Subject: [PATCH 030/636] [feat] add enableSourcemap option (#6835)
---
site/content/docs/04-compile-time.md | 2 ++
src/compiler/compile/Component.ts | 30 ++++++++++++-------
src/compiler/compile/index.ts | 3 +-
src/compiler/compile/render_dom/index.ts | 13 ++++++--
src/compiler/compile/render_ssr/index.ts | 5 +++-
.../compile/utils/check_enable_sourcemap.ts | 10 +++++++
src/compiler/interfaces.ts | 3 ++
test/sourcemaps/index.ts | 12 ++++----
.../samples/no-sourcemap/_config.js | 5 ++++
.../samples/no-sourcemap/input.svelte | 11 +++++++
test/sourcemaps/samples/no-sourcemap/test.js | 4 +++
.../samples/only-css-sourcemap/_config.js | 5 ++++
.../samples/only-css-sourcemap/input.svelte | 11 +++++++
.../samples/only-css-sourcemap/test.js | 4 +++
.../samples/only-js-sourcemap/_config.js | 5 ++++
.../samples/only-js-sourcemap/input.svelte | 11 +++++++
.../samples/only-js-sourcemap/test.js | 4 +++
17 files changed, 117 insertions(+), 21 deletions(-)
create mode 100644 src/compiler/compile/utils/check_enable_sourcemap.ts
create mode 100644 test/sourcemaps/samples/no-sourcemap/_config.js
create mode 100644 test/sourcemaps/samples/no-sourcemap/input.svelte
create mode 100644 test/sourcemaps/samples/no-sourcemap/test.js
create mode 100644 test/sourcemaps/samples/only-css-sourcemap/_config.js
create mode 100644 test/sourcemaps/samples/only-css-sourcemap/input.svelte
create mode 100644 test/sourcemaps/samples/only-css-sourcemap/test.js
create mode 100644 test/sourcemaps/samples/only-js-sourcemap/_config.js
create mode 100644 test/sourcemaps/samples/only-js-sourcemap/input.svelte
create mode 100644 test/sourcemaps/samples/only-js-sourcemap/test.js
diff --git a/site/content/docs/04-compile-time.md b/site/content/docs/04-compile-time.md
index ed6977f81f..8e709d7c37 100644
--- a/site/content/docs/04-compile-time.md
+++ b/site/content/docs/04-compile-time.md
@@ -82,6 +82,8 @@ The following options can be passed to the compiler. None are required:
| `loopGuardTimeout` | 0 | A `number` that tells Svelte to break the loop if it blocks the thread for more than `loopGuardTimeout` ms. This is useful to prevent infinite loops. **Only available when `dev: true`**
| `preserveComments` | `false` | If `true`, your HTML comments will be preserved during server-side rendering. By default, they are stripped out.
| `preserveWhitespace` | `false` | If `true`, whitespace inside and between elements is kept as you typed it, rather than removed or collapsed to a single space where possible.
+| `sourcemap` | `object | string` | An initial sourcemap that will be merged into the final output sourcemap. This is usually the preprocessor sourcemap.
+| `enableSourcemap` | `boolean | { js: boolean; css: boolean; }` | If `true`, Svelte generate sourcemaps for components. Use an object with `js` or `css` for more granular control of sourcemap generation. By default, this is `true`.
| `outputFilename` | `null` | A `string` used for your JavaScript sourcemap.
| `cssOutputFilename` | `null` | A `string` used for your CSS sourcemap.
| `sveltePath` | `"svelte"` | The location of the `svelte` package. Any imports from `svelte` or `svelte/[module]` will be modified accordingly.
diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts
index 202e14fd98..4d4cf909fd 100644
--- a/src/compiler/compile/Component.ts
+++ b/src/compiler/compile/Component.ts
@@ -36,6 +36,7 @@ import { clone } from '../utils/clone';
import compiler_warnings from './compiler_warnings';
import compiler_errors from './compiler_errors';
import { extract_ignores_above_position, extract_svelte_ignore_from_comments } from '../utils/extract_svelte_ignore';
+import check_enable_sourcemap from './utils/check_enable_sourcemap';
interface ComponentOptions {
namespace?: string;
@@ -343,21 +344,28 @@ export default class Component {
? { code: null, map: null }
: result.css;
- const sourcemap_source_filename = get_sourcemap_source_filename(compile_options);
+ const js_sourcemap_enabled = check_enable_sourcemap(compile_options.enableSourcemap, 'js');
- js = print(program, {
- sourceMapSource: sourcemap_source_filename
- });
+ if (!js_sourcemap_enabled) {
+ js = print(program);
+ js.map = null;
+ } else {
+ const sourcemap_source_filename = get_sourcemap_source_filename(compile_options);
- js.map.sources = [
- sourcemap_source_filename
- ];
+ js = print(program, {
+ sourceMapSource: sourcemap_source_filename
+ });
- js.map.sourcesContent = [
- this.source
- ];
+ js.map.sources = [
+ sourcemap_source_filename
+ ];
- js.map = apply_preprocessor_sourcemap(sourcemap_source_filename, js.map, compile_options.sourcemap as (string | RawSourceMap | DecodedSourceMap));
+ js.map.sourcesContent = [
+ this.source
+ ];
+
+ js.map = apply_preprocessor_sourcemap(sourcemap_source_filename, js.map, compile_options.sourcemap as (string | RawSourceMap | DecodedSourceMap));
+ }
}
return {
diff --git a/src/compiler/compile/index.ts b/src/compiler/compile/index.ts
index 96b24bceee..afe9c56cf4 100644
--- a/src/compiler/compile/index.ts
+++ b/src/compiler/compile/index.ts
@@ -13,6 +13,7 @@ const valid_options = [
'name',
'filename',
'sourcemap',
+ 'enableSourcemap',
'generate',
'errorMode',
'varsReport',
@@ -82,7 +83,7 @@ function validate_options(options: CompileOptions, warnings: Warning[]) {
}
export default function compile(source: string, options: CompileOptions = {}) {
- options = Object.assign({ generate: 'dom', dev: false }, options);
+ options = Object.assign({ generate: 'dom', dev: false, enableSourcemap: true }, options);
const stats = new Stats();
const warnings = [];
diff --git a/src/compiler/compile/render_dom/index.ts b/src/compiler/compile/render_dom/index.ts
index f74f4cdf1c..89af0c297c 100644
--- a/src/compiler/compile/render_dom/index.ts
+++ b/src/compiler/compile/render_dom/index.ts
@@ -10,6 +10,7 @@ import { ImportDeclaration, ClassDeclaration, FunctionExpression, Node, Statemen
import { apply_preprocessor_sourcemap } from '../../utils/mapped_code';
import { RawSourceMap, DecodedSourceMap } from '@ampproject/remapping/dist/types/types';
import { flatten } from '../../utils/flatten';
+import check_enable_sourcemap from '../utils/check_enable_sourcemap';
export default function dom(
component: Component,
@@ -34,9 +35,15 @@ export default function dom(
const css = component.stylesheet.render(options.filename, !options.customElement);
- css.map = apply_preprocessor_sourcemap(options.filename, css.map, options.sourcemap as string | RawSourceMap | DecodedSourceMap);
+ const css_sourcemap_enabled = check_enable_sourcemap(options.enableSourcemap, 'css');
- const styles = component.stylesheet.has_styles && options.dev
+ if (css_sourcemap_enabled) {
+ css.map = apply_preprocessor_sourcemap(options.filename, css.map, options.sourcemap as string | RawSourceMap | DecodedSourceMap);
+ } else {
+ css.map = null;
+ }
+
+ const styles = css_sourcemap_enabled && component.stylesheet.has_styles && options.dev
? `${css.code}\n/*# sourceMappingURL=${css.map.toUrl()} */`
: css.code;
@@ -521,7 +528,7 @@ export default function dom(
constructor(options) {
super();
- ${css.code && b`this.shadowRoot.innerHTML = \`\`;`}
+ ${css.code && b`this.shadowRoot.innerHTML = \`\`;`}
@init(this, { target: this.shadowRoot, props: ${init_props}, customElement: true }, ${definition}, ${has_create_fragment ? 'create_fragment' : 'null'}, ${not_equal}, ${prop_indexes}, null, ${dirty});
diff --git a/src/compiler/compile/render_ssr/index.ts b/src/compiler/compile/render_ssr/index.ts
index b35a6ce6ff..9d2c1cc60b 100644
--- a/src/compiler/compile/render_ssr/index.ts
+++ b/src/compiler/compile/render_ssr/index.ts
@@ -10,6 +10,7 @@ import { extract_names } from 'periscopic';
import { walk } from 'estree-walker';
import { invalidate } from '../render_dom/invalidate';
+import check_enable_sourcemap from '../utils/check_enable_sourcemap';
export default function ssr(
component: Component,
@@ -200,11 +201,13 @@ export default function ssr(
main
].filter(Boolean);
+ const css_sourcemap_enabled = check_enable_sourcemap(options.enableSourcemap, 'css');
+
const js = b`
${css.code ? b`
const #css = {
code: "${css.code}",
- map: ${css.map ? string_literal(css.map.toString()) : 'null'}
+ map: ${css_sourcemap_enabled && css.map ? string_literal(css.map.toString()) : 'null'}
};` : null}
${component.extract_javascript(component.ast.module)}
diff --git a/src/compiler/compile/utils/check_enable_sourcemap.ts b/src/compiler/compile/utils/check_enable_sourcemap.ts
new file mode 100644
index 0000000000..51f07c353a
--- /dev/null
+++ b/src/compiler/compile/utils/check_enable_sourcemap.ts
@@ -0,0 +1,10 @@
+import { EnableSourcemap } from '../../interfaces';
+
+export default function check_enable_sourcemap(
+ enable_sourcemap: EnableSourcemap,
+ namespace: keyof Extract
+) {
+ return typeof enable_sourcemap === 'boolean'
+ ? enable_sourcemap
+ : enable_sourcemap[namespace];
+}
diff --git a/src/compiler/interfaces.ts b/src/compiler/interfaces.ts
index 7446c4c14b..b999fbd803 100644
--- a/src/compiler/interfaces.ts
+++ b/src/compiler/interfaces.ts
@@ -131,6 +131,8 @@ export interface Warning {
export type ModuleFormat = 'esm' | 'cjs';
+export type EnableSourcemap = boolean | { js: boolean; css: boolean };
+
export type CssHashGetter = (args: {
name: string;
filename: string | undefined;
@@ -147,6 +149,7 @@ export interface CompileOptions {
varsReport?: 'full' | 'strict' | false;
sourcemap?: object | string;
+ enableSourcemap?: EnableSourcemap;
outputFilename?: string;
cssOutputFilename?: string;
sveltePath?: string;
diff --git a/test/sourcemaps/index.ts b/test/sourcemaps/index.ts
index 903629c06b..fc021cd6a7 100644
--- a/test/sourcemaps/index.ts
+++ b/test/sourcemaps/index.ts
@@ -85,11 +85,13 @@ describe('sourcemaps', () => {
);
}
- assert.deepEqual(
- js.map.sources.slice().sort(),
- (config.js_map_sources || ['input.svelte']).sort(),
- 'js.map.sources is wrong'
- );
+ if (js.map) {
+ assert.deepEqual(
+ js.map.sources.slice().sort(),
+ (config.js_map_sources || ['input.svelte']).sort(),
+ 'js.map.sources is wrong'
+ );
+ }
if (css.map) {
assert.deepEqual(
css.map.sources.slice().sort(),
diff --git a/test/sourcemaps/samples/no-sourcemap/_config.js b/test/sourcemaps/samples/no-sourcemap/_config.js
new file mode 100644
index 0000000000..5b84d40554
--- /dev/null
+++ b/test/sourcemaps/samples/no-sourcemap/_config.js
@@ -0,0 +1,5 @@
+export default {
+ compile_options: {
+ enableSourcemap: false
+ }
+};
diff --git a/test/sourcemaps/samples/no-sourcemap/input.svelte b/test/sourcemaps/samples/no-sourcemap/input.svelte
new file mode 100644
index 0000000000..6d39eaad0e
--- /dev/null
+++ b/test/sourcemaps/samples/no-sourcemap/input.svelte
@@ -0,0 +1,11 @@
+
+
+
\ No newline at end of file
+
From 7681ed0a4596192b5b55839e6920223316a88d73 Mon Sep 17 00:00:00 2001
From: gtmnayan <50981692+gtm-nayan@users.noreply.github.com>
Date: Mon, 8 Nov 2021 12:19:04 +0545
Subject: [PATCH 050/636] [docs] Document the effect of the order of bind: and
on: (#6887)
---
site/content/docs/02-template-syntax.md | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/site/content/docs/02-template-syntax.md b/site/content/docs/02-template-syntax.md
index 373e0879af..f57eb675ec 100644
--- a/site/content/docs/02-template-syntax.md
+++ b/site/content/docs/02-template-syntax.md
@@ -602,6 +602,22 @@ On `` elements with `type="file"`, you can use `bind:files` to get the [`
/>
```
+---
+
+`bind:` can be used together with `on:` directives. The order that they are defined in determines the value of the bound variable when the event handler is called.
+
+```sv
+
+
+
+```
+
##### Binding `