Skip to content

Commit

Permalink
feat: adds legacy mode flag
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm committed Nov 6, 2024
1 parent d033377 commit f9fe9f0
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/warm-snakes-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

feat: adds legacy mode flag
3 changes: 3 additions & 0 deletions packages/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
"./internal/disclose-version": {
"default": "./src/internal/disclose-version.js"
},
"./internal/legacy-component": {
"default": "./src/internal/legacy-component.js"
},
"./internal/server": {
"default": "./src/internal/server/index.js"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,10 @@ export function client_component(analysis, options) {
body.push(b.stmt(b.call(b.id('$.mark_module_end'), b.id(analysis.name))));
}

if (!analysis.runes) {
body.unshift(b.imports([], 'svelte/internal/legacy-component'));
}

if (options.discloseVersion) {
body.unshift(b.imports([], 'svelte/internal/disclose-version'));
}
Expand Down
3 changes: 2 additions & 1 deletion packages/svelte/src/internal/client/reactivity/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import * as e from '../errors.js';
import { BRANCH_EFFECT, LEGACY_DERIVED_PROP, ROOT_EFFECT } from '../constants.js';
import { proxy } from '../proxy.js';
import { capture_store_binding } from './store.js';
import { legacy_mode_flag } from '../../feature-flags.js';

/**
* @param {((value?: number) => number)} fn
Expand Down Expand Up @@ -270,7 +271,7 @@ function with_parent_branch(fn) {
*/
export function prop(props, key, flags, fallback) {
var immutable = (flags & PROPS_IS_IMMUTABLE) !== 0;
var runes = (flags & PROPS_IS_RUNES) !== 0;
var runes = !legacy_mode_flag || (flags & PROPS_IS_RUNES) !== 0;
var bindable = (flags & PROPS_IS_BINDABLE) !== 0;
var lazy = (flags & PROPS_IS_LAZY_INITIAL) !== 0;
var is_store_sub = false;
Expand Down
5 changes: 3 additions & 2 deletions packages/svelte/src/internal/client/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { destroy_derived, execute_derived, update_derived } from './reactivity/d
import * as e from './errors.js';
import { lifecycle_outside_component } from '../shared/errors.js';
import { FILENAME } from '../../constants.js';
import { legacy_mode_flag } from '../feature-flags.js';

const FLUSH_MICROTASK = 0;
const FLUSH_SYNC = 1;
Expand Down Expand Up @@ -162,7 +163,7 @@ export function increment_version() {

/** @returns {boolean} */
export function is_runes() {
return component_context !== null && component_context.l === null;
return !legacy_mode_flag || (component_context !== null && component_context.l === null);
}

/**
Expand Down Expand Up @@ -1025,7 +1026,7 @@ export function push(props, runes = false, fn) {
l: null
};

if (!runes) {
if (legacy_mode_flag && !runes) {
component_context.l = {
s: null,
u: null,
Expand Down
5 changes: 5 additions & 0 deletions packages/svelte/src/internal/feature-flags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export let legacy_mode_flag = false;

export function enable_legacy_mode_flag() {
legacy_mode_flag = true;
}
3 changes: 3 additions & 0 deletions packages/svelte/src/internal/legacy-component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { enable_legacy_mode_flag } from './feature-flags.js';

enable_legacy_mode_flag();
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
</script>

{count} / {doubled} / {quadrupled} / {time_8} / {time_16}
{count} / {doubled} / {quadrupled} / {time_8} / {time_16}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
{readonly}
{optional}
<input bind:value={binding} />
<input bind:value={bindingOptional} />
<input bind:value={bindingOptional} />
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "svelte/internal/disclose-version";
import "svelte/internal/legacy-component";
import * as $ from "svelte/internal/client";

export default function Bind_this($$anchor) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "svelte/internal/disclose-version";
import "svelte/internal/legacy-component";
import * as $ from "svelte/internal/client";

export default function Each_string_template($$anchor) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "svelte/internal/disclose-version";
import "svelte/internal/legacy-component";
import * as $ from "svelte/internal/client";

var root = $.template(`<h1>hello world</h1>`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "svelte/internal/disclose-version";
import "svelte/internal/legacy-component";
import * as $ from "svelte/internal/client";

var root = $.template(`<h1>hello world</h1>`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "svelte/internal/disclose-version";
import "svelte/internal/legacy-component";
import * as $ from "svelte/internal/client";
import { random } from './module.svelte';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "svelte/internal/disclose-version";
import "svelte/internal/legacy-component";
import * as $ from "svelte/internal/client";

var root = $.template(`<p></p> <p></p> <!>`, 1);
Expand Down

0 comments on commit f9fe9f0

Please sign in to comment.