Skip to content

Commit 29ce01e

Browse files
committed
fix
1 parent 2a8dcdb commit 29ce01e

File tree

6 files changed

+18
-38
lines changed

6 files changed

+18
-38
lines changed

packages/svelte/src/compiler/phases/2-analyze/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as e from '../../errors.js';
77
import * as w from '../../warnings.js';
88
import { is_text_attribute } from '../../utils/ast.js';
99
import * as b from '../../utils/builders.js';
10-
import { ReservedKeywords, Runes } from '../constants.js';
10+
import { Runes } from '../constants.js';
1111
import { Scope, ScopeRoot, create_scopes, get_rune } from '../scope.js';
1212
import check_graph_for_cycles from './utils/check_graph_for_cycles.js';
1313
import { create_attribute } from '../nodes.js';
@@ -203,6 +203,8 @@ function get_component_name(filename) {
203203
return name[0].toUpperCase() + name.slice(1);
204204
}
205205

206+
const RESERVED = ['$$props', '$$restProps', '$$slots'];
207+
206208
/**
207209
* @param {Program} ast
208210
* @param {ValidatedModuleCompileOptions} options
@@ -212,7 +214,7 @@ export function analyze_module(ast, options) {
212214
const { scope, scopes } = create_scopes(ast, new ScopeRoot(), false, null);
213215

214216
for (const [name, references] of scope.references) {
215-
if (name[0] !== '$' || ReservedKeywords.includes(name)) continue;
217+
if (name[0] !== '$' || RESERVED.includes(name)) continue;
216218
if (name === '$' || name[1] === '$') {
217219
e.global_reference_invalid(references[0].node, name);
218220
}
@@ -257,7 +259,7 @@ export function analyze_component(root, source, options) {
257259

258260
// create synthetic bindings for store subscriptions
259261
for (const [name, references] of module.scope.references) {
260-
if (name[0] !== '$' || ReservedKeywords.includes(name)) continue;
262+
if (name[0] !== '$' || RESERVED.includes(name)) continue;
261263
if (name === '$' || name[1] === '$') {
262264
e.global_reference_invalid(references[0].node, name);
263265
}

packages/svelte/src/compiler/phases/2-analyze/visitors/BindDirective.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { validate_no_const_assignment } from './shared/utils.js';
99
import * as e from '../../../errors.js';
1010
import * as w from '../../../warnings.js';
1111
import { binding_properties } from '../../bindings.js';
12-
import { ContentEditableBindings, SVGElements } from '../../constants.js';
12+
import { CONTENT_EDITABLE_BINDINGS, SVGElements } from '../../constants.js';
1313
import fuzzymatch from '../../1-parse/utils/fuzzymatch.js';
1414

1515
/**
@@ -205,7 +205,7 @@ export function BindDirective(node, context) {
205205
);
206206
}
207207

208-
if (ContentEditableBindings.includes(node.name)) {
208+
if (CONTENT_EDITABLE_BINDINGS.includes(node.name)) {
209209
const contenteditable = /** @type {Attribute} */ (
210210
parent.attributes.find((a) => a.type === 'Attribute' && a.name === 'contenteditable')
211211
);

packages/svelte/src/compiler/phases/2-analyze/visitors/shared/a11y.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import * as w from '../../../../warnings.js';
1515
import fuzzymatch from '../../../1-parse/utils/fuzzymatch.js';
1616
import { is_event_attribute, is_text_attribute } from '../../../../utils/ast.js';
17-
import { ContentEditableBindings } from '../../../constants.js';
17+
import { CONTENT_EDITABLE_BINDINGS } from '../../../constants.js';
1818
import { walk } from 'zimmerframe';
1919
import { list } from '../../../../utils/string.js';
2020

@@ -722,7 +722,7 @@ export function check_element(node, state) {
722722
}
723723
} else if (
724724
attribute.type === 'BindDirective' &&
725-
ContentEditableBindings.includes(attribute.name)
725+
CONTENT_EDITABLE_BINDINGS.includes(attribute.name)
726726
) {
727727
has_contenteditable_binding = true;
728728
}

packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/element.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ import {
77
is_text_attribute
88
} from '../../../../../utils/ast.js';
99
import { binding_properties } from '../../../../bindings.js';
10-
import {
11-
ContentEditableBindings,
12-
LoadErrorElements,
13-
WhitespaceInsensitiveAttributes
14-
} from '../../../../constants.js';
10+
import { CONTENT_EDITABLE_BINDINGS, LoadErrorElements } from '../../../../constants.js';
1511
import {
1612
create_attribute,
1713
create_expression_metadata,
@@ -26,6 +22,8 @@ import {
2622
import { serialize_attribute_value } from './utils.js';
2723
import { is_boolean_attribute } from '../../../../../../utils.js';
2824

25+
const WHITESPACE_INSENSITIVE_ATTRIBUTES = ['class', 'style'];
26+
2927
/**
3028
* Writes the output to the template output. Some elements may have attributes on them that require the
3129
* their output to be the child content instead. In this case, an object is returned.
@@ -108,7 +106,7 @@ export function serialize_element_attributes(node, context) {
108106
const binding = binding_properties[attribute.name];
109107
if (binding?.omit_in_ssr) continue;
110108

111-
if (ContentEditableBindings.includes(attribute.name)) {
109+
if (CONTENT_EDITABLE_BINDINGS.includes(attribute.name)) {
112110
content = /** @type {Expression} */ (context.visit(attribute.expression));
113111
} else if (attribute.name === 'value' && node.name === 'textarea') {
114112
content = b.call(
@@ -227,7 +225,7 @@ export function serialize_element_attributes(node, context) {
227225
serialize_attribute_value(
228226
attribute.value,
229227
context,
230-
WhitespaceInsensitiveAttributes.includes(name)
228+
WHITESPACE_INSENSITIVE_ATTRIBUTES.includes(name)
231229
)
232230
).value;
233231
if (name !== 'class' || literal_value) {
@@ -248,7 +246,7 @@ export function serialize_element_attributes(node, context) {
248246
const value = serialize_attribute_value(
249247
attribute.value,
250248
context,
251-
WhitespaceInsensitiveAttributes.includes(name)
249+
WHITESPACE_INSENSITIVE_ATTRIBUTES.includes(name)
252250
);
253251

254252
context.state.template.push(
@@ -343,7 +341,7 @@ function serialize_element_spread_attributes(
343341
const value = serialize_attribute_value(
344342
attribute.value,
345343
context,
346-
WhitespaceInsensitiveAttributes.includes(name)
344+
WHITESPACE_INSENSITIVE_ATTRIBUTES.includes(name)
347345
);
348346
return b.prop('init', b.key(name), value);
349347
}

packages/svelte/src/compiler/phases/constants.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,9 @@ export const Runes = /** @type {const} */ ([
2222
* list is almost certainly very incomplete)
2323
* TODO this is currently unused
2424
*/
25-
export const ElementsWithoutText = ['audio', 'datalist', 'dl', 'optgroup', 'select', 'video'];
25+
export const ELEMENTS_WITHOUT_TEXT = ['audio', 'datalist', 'dl', 'optgroup', 'select', 'video'];
2626

27-
export const ReservedKeywords = ['$$props', '$$restProps', '$$slots'];
28-
29-
/** Attributes where whitespace can be compacted */
30-
export const WhitespaceInsensitiveAttributes = ['class', 'style'];
31-
32-
export const ContentEditableBindings = ['textContent', 'innerHTML', 'innerText'];
27+
export const CONTENT_EDITABLE_BINDINGS = ['textContent', 'innerHTML', 'innerText'];
3328

3429
export const LoadErrorElements = [
3530
'body',

packages/svelte/src/constants.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,6 @@ export const UNINITIALIZED = Symbol();
3434
export const FILENAME = Symbol('filename');
3535
export const HMR = Symbol('hmr');
3636

37-
/**
38-
* @type {Record<string, string>}
39-
* List of attribute names that should be aliased to their property names
40-
* because they behave differently between setting them as an attribute and
41-
* setting them as a property.
42-
*/
43-
export const ATTRIBUTE_ALIASES = {
44-
// no `class: 'className'` because we handle that separately
45-
formnovalidate: 'formNoValidate',
46-
ismap: 'isMap',
47-
nomodule: 'noModule',
48-
playsinline: 'playsInline',
49-
readonly: 'readOnly'
50-
};
51-
5237
export const NAMESPACE_SVG = 'http://www.w3.org/2000/svg';
5338
export const NAMESPACE_MATHML = 'http://www.w3.org/1998/Math/MathML';
5439

0 commit comments

Comments
 (0)