Skip to content

Commit

Permalink
Merge branch 'main' into fix-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm committed May 22, 2024
2 parents 238c9b2 + 4f9096a commit e95fad3
Show file tree
Hide file tree
Showing 64 changed files with 788 additions and 171 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-maps-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: allow comments after last selector in css
5 changes: 5 additions & 0 deletions .changeset/itchy-beds-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: don't add scoping modifier to nesting selectors
5 changes: 5 additions & 0 deletions .changeset/kind-snakes-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: migrate derivations without semicolons
5 changes: 5 additions & 0 deletions .changeset/mean-jokes-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

chore: speedup hydration around input and select values
5 changes: 5 additions & 0 deletions .changeset/plenty-elephants-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: check for invalid bindings on window and document
10 changes: 10 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"chilly-snakes-scream",
"clean-eels-beg",
"clever-chefs-relate",
"clever-maps-travel",
"clever-rockets-burn",
"clever-sloths-push",
"cold-birds-own",
Expand Down Expand Up @@ -208,6 +209,7 @@
"hungry-tips-unite",
"hungry-trees-travel",
"itchy-beans-melt",
"itchy-beds-kneel",
"itchy-bulldogs-tan",
"itchy-eels-marry",
"itchy-kings-deliver",
Expand All @@ -227,6 +229,7 @@
"kind-dots-sort",
"kind-eagles-join",
"kind-rings-flash",
"kind-snakes-drive",
"kind-spoons-return",
"large-clouds-carry",
"large-turkeys-deny",
Expand Down Expand Up @@ -267,6 +270,7 @@
"lucky-toes-begin",
"many-rockets-give",
"many-trees-fix",
"mean-jokes-exist",
"metal-clouds-raise",
"metal-lobsters-burn",
"mighty-cooks-scream",
Expand Down Expand Up @@ -318,6 +322,7 @@
"pink-bikes-agree",
"pink-goats-promise",
"pink-mayflies-tie",
"plenty-elephants-fry",
"plenty-starfishes-dress",
"plenty-zoos-fix",
"polite-dolphins-care",
Expand All @@ -338,7 +343,9 @@
"purple-dragons-peel",
"quiet-apricots-dream",
"quiet-berries-end",
"quiet-berries-explode",
"quiet-camels-mate",
"quiet-cobras-smile",
"quiet-crabs-nail",
"quiet-timers-speak",
"rare-mirrors-act",
Expand Down Expand Up @@ -431,6 +438,7 @@
"soft-tigers-wink",
"sour-bags-fail",
"sour-forks-stare",
"sour-jeans-collect",
"sour-rules-march",
"sour-weeks-fix",
"spicy-jeans-deliver",
Expand Down Expand Up @@ -465,6 +473,7 @@
"tall-shrimps-worry",
"tall-tigers-wait",
"tame-cycles-kneel",
"tame-dots-battle",
"tame-spies-drum",
"tasty-cheetahs-appear",
"tasty-numbers-perform",
Expand Down Expand Up @@ -503,6 +512,7 @@
"tiny-meals-deliver",
"tiny-moose-kiss",
"tough-radios-punch",
"twelve-beans-drive",
"twelve-dragons-join",
"twelve-onions-juggle",
"twelve-worms-jog",
Expand Down
5 changes: 5 additions & 0 deletions .changeset/quiet-cobras-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: inline pointer events now correctly work in Chrome
5 changes: 5 additions & 0 deletions .changeset/sour-jeans-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: update value like attributes in a separate template_effect
5 changes: 5 additions & 0 deletions .changeset/tame-dots-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: improve handling of unowned derived signal
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ coverage
.env.test

# build output
dist
.vercel

# OS-specific
Expand Down
28 changes: 28 additions & 0 deletions packages/svelte/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# svelte

## 5.0.0-next.138

### Patch Changes

- fix: allow comments after last selector in css ([#11723](https://github.com/sveltejs/svelte/pull/11723))

- fix: don't add scoping modifier to nesting selectors ([#11713](https://github.com/sveltejs/svelte/pull/11713))

- chore: speedup hydration around input and select values ([#11717](https://github.com/sveltejs/svelte/pull/11717))

- fix: update value like attributes in a separate template_effect ([#11720](https://github.com/sveltejs/svelte/pull/11720))

- fix: improve handling of unowned derived signal ([#11712](https://github.com/sveltejs/svelte/pull/11712))

## 5.0.0-next.137

### Patch Changes

- fix: migrate derivations without semicolons ([#11704](https://github.com/sveltejs/svelte/pull/11704))

- fix: check for invalid bindings on window and document ([#11676](https://github.com/sveltejs/svelte/pull/11676))

- fix: more efficient spread attributes in SSR output ([#11660](https://github.com/sveltejs/svelte/pull/11660))

- fix: inline pointer events now correctly work in Chrome ([#11695](https://github.com/sveltejs/svelte/pull/11695))

- fix: don't require warning codes to be separated by commas in non-runes mode ([#11669](https://github.com/sveltejs/svelte/pull/11669))

## 5.0.0-next.136

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "svelte",
"description": "Cybernetically enhanced web apps",
"license": "MIT",
"version": "5.0.0-next.136",
"version": "5.0.0-next.138",
"type": "module",
"types": "./types/index.d.ts",
"engines": {
Expand Down
14 changes: 9 additions & 5 deletions packages/svelte/src/compiler/migrate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,15 @@ const instance_script = {
/** @type {number} */ (node.body.expression.right.start),
'$derived('
);
state.str.update(
/** @type {number} */ (node.body.expression.right.end),
/** @type {number} */ (node.end),
');'
);
if (node.body.expression.right.end !== node.end) {
state.str.update(
/** @type {number} */ (node.body.expression.right.end),
/** @type {number} */ (node.end),
');'
);
} else {
state.str.appendRight(/** @type {number} */ (node.end), ');');
}
return;
} else {
for (const binding of reassigned_bindings) {
Expand Down
4 changes: 2 additions & 2 deletions packages/svelte/src/compiler/phases/1-parse/read/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function read_selector_list(parser, inside_pseudo_class = false) {

const end = parser.index;

parser.allow_whitespace();
allow_comment_or_whitespace(parser);

if (inside_pseudo_class ? parser.match(')') : parser.match('{')) {
return {
Expand Down Expand Up @@ -324,7 +324,7 @@ function read_selector(parser, inside_pseudo_class = false) {
}

const index = parser.index;
parser.allow_whitespace();
allow_comment_or_whitespace(parser);

if (parser.match(',') || (inside_pseudo_class ? parser.match(')') : parser.match('{'))) {
// rewind, so we know whether to continue building the selector list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export default function tag(parser) {
while ((attribute = read(parser))) {
if (attribute.type === 'Attribute' || attribute.type === 'BindDirective') {
if (unique_names.includes(attribute.name)) {
e.attribute_duplicate(attribute.start);
e.attribute_duplicate(attribute);
// <svelte:element bind:this this=..> is allowed
} else if (attribute.name !== 'this') {
unique_names.push(attribute.name);
Expand Down
17 changes: 17 additions & 0 deletions packages/svelte/src/compiler/phases/2-analyze/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,23 @@ const validation = {
);
}

if (property.invalid_elements && property.invalid_elements.includes(parent.name)) {
const valid_bindings = Object.entries(binding_properties)
.filter(([_, binding_property]) => {
return (
binding_property.valid_elements?.includes(parent.name) ||
(!binding_property.valid_elements &&
!binding_property.invalid_elements?.includes(parent.name))
);
})
.map(([property_name]) => property_name);
e.bind_invalid_name(
node,
node.name,
`Possible bindings for <${parent.name}> are ${valid_bindings.join(', ')}`
);
}

if (parent.name === 'input' && node.name !== 'this') {
const type = /** @type {import('#compiler').Attribute | undefined} */ (
parent.attributes.find((a) => a.type === 'Attribute' && a.name === 'type')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,10 @@ function serialize_element_attribute_update_assignment(element, node_id, attribu
value
)
);
} else if (name === 'value') {
update = b.stmt(b.call('$.set_value', node_id, value));
} else if (name === 'checked') {
update = b.stmt(b.call('$.set_checked', node_id, value));
} else if (DOMProperties.includes(name)) {
update = b.stmt(b.assignment('=', b.member(node_id, b.id(name)), value));
} else {
Expand Down Expand Up @@ -1990,7 +1994,7 @@ export const template_visitors = {
child_metadata.bound_contenteditable = true;
}

if (needs_input_reset && (node.name === 'input' || node.name === 'select')) {
if (needs_input_reset && node.name === 'input') {
context.state.init.push(b.stmt(b.call('$.remove_input_attr_defaults', context.state.node)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ const visitors = {
}
}

if (relative_selector.selectors.every((s) => s.type === 'NestingSelector')) {
if (relative_selector.selectors.some((s) => s.type === 'NestingSelector')) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1851,18 +1851,27 @@ function serialize_element_attributes(node, context) {

for (const attribute of node.attributes) {
if (attribute.type === 'Attribute') {
if (attribute.name === 'value' && node.name === 'textarea') {
if (
attribute.value !== true &&
attribute.value[0].type === 'Text' &&
regex_starts_with_newline.test(attribute.value[0].data)
) {
// Two or more leading newlines are required to restore the leading newline immediately after `<textarea>`.
// see https://html.spec.whatwg.org/multipage/syntax.html#element-restrictions
// also see related code in analysis phase
attribute.value[0].data = '\n' + attribute.value[0].data;
if (attribute.name === 'value') {
if (node.name === 'textarea') {
if (
attribute.value !== true &&
attribute.value[0].type === 'Text' &&
regex_starts_with_newline.test(attribute.value[0].data)
) {
// Two or more leading newlines are required to restore the leading newline immediately after `<textarea>`.
// see https://html.spec.whatwg.org/multipage/syntax.html#element-restrictions
// also see related code in analysis phase
attribute.value[0].data = '\n' + attribute.value[0].data;
}
content = {
escape: true,
expression: serialize_attribute_value(attribute.value, context)
};
} else if (node.name !== 'select') {
// omit value attribute for select elements, it's irrelevant for the initially selected value and has no
// effect on the selected value after the user interacts with the select element (the value _property_ does, but not the attribute)
attributes.push(attribute);
}
content = { escape: true, expression: serialize_attribute_value(attribute.value, context) };

// omit event handlers except for special cases
} else if (is_event_attribute(attribute)) {
Expand Down
37 changes: 26 additions & 11 deletions packages/svelte/src/compiler/phases/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @property {string} [type] Set this to `set` if updates are written to the dom property
* @property {boolean} [omit_in_ssr] Set this to true if the binding should not be included in SSR
* @property {string[]} [valid_elements] If this is set, the binding is only valid on the given elements
* @property {string[]} [invalid_elements] If this is set, the binding is invalid on the given elements
*/

/**
Expand Down Expand Up @@ -131,28 +132,36 @@ export const binding_properties = {
},
// dimensions
clientWidth: {
omit_in_ssr: true
omit_in_ssr: true,
invalid_elements: ['svelte:window', 'svelte:document']
},
clientHeight: {
omit_in_ssr: true
omit_in_ssr: true,
invalid_elements: ['svelte:window', 'svelte:document']
},
offsetWidth: {
omit_in_ssr: true
omit_in_ssr: true,
invalid_elements: ['svelte:window', 'svelte:document']
},
offsetHeight: {
omit_in_ssr: true
omit_in_ssr: true,
invalid_elements: ['svelte:window', 'svelte:document']
},
contentRect: {
omit_in_ssr: true
omit_in_ssr: true,
invalid_elements: ['svelte:window', 'svelte:document']
},
contentBoxSize: {
omit_in_ssr: true
omit_in_ssr: true,
invalid_elements: ['svelte:window', 'svelte:document']
},
borderBoxSize: {
omit_in_ssr: true
omit_in_ssr: true,
invalid_elements: ['svelte:window', 'svelte:document']
},
devicePixelContentBoxSize: {
omit_in_ssr: true
omit_in_ssr: true,
invalid_elements: ['svelte:window', 'svelte:document']
},
// checkbox/radio
indeterminate: {
Expand All @@ -171,9 +180,15 @@ export const binding_properties = {
this: {
omit_in_ssr: true
},
innerText: {},
innerHTML: {},
textContent: {},
innerText: {
invalid_elements: ['svelte:window', 'svelte:document']
},
innerHTML: {
invalid_elements: ['svelte:window', 'svelte:document']
},
textContent: {
invalid_elements: ['svelte:window', 'svelte:document']
},
open: {
event: 'toggle',
type: 'set',
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const DelegatedEvents = [
'contextmenu',
'focusin',
'focusout',
// 'input', This conflicts with bind:input
'input',
'keydown',
'keyup',
'mousedown',
Expand Down
Loading

0 comments on commit e95fad3

Please sign in to comment.