Skip to content

Commit 2556867

Browse files
committed
revert some stuff
1 parent 7c9b11d commit 2556867

File tree

2 files changed

+58
-58
lines changed

2 files changed

+58
-58
lines changed

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,59 @@ export function analyze_component(root, options) {
466466
for (const element of analysis.elements) {
467467
prune(analysis.css.ast, element);
468468
}
469+
470+
outer: for (const element of analysis.elements) {
471+
if (element.metadata.scoped) {
472+
// Dynamic elements in dom mode always use spread for attributes and therefore shouldn't have a class attribute added to them
473+
// TODO this happens during the analysis phase, which shouldn't know anything about client vs server
474+
if (element.type === 'SvelteElement' && options.generate === 'client') continue;
475+
476+
/** @type {import('#compiler').Attribute | undefined} */
477+
let class_attribute = undefined;
478+
479+
for (const attribute of element.attributes) {
480+
if (attribute.type === 'SpreadAttribute') {
481+
// The spread method appends the hash to the end of the class attribute on its own
482+
continue outer;
483+
}
484+
485+
if (attribute.type !== 'Attribute') continue;
486+
if (attribute.name.toLowerCase() !== 'class') continue;
487+
488+
class_attribute = attribute;
489+
}
490+
491+
if (class_attribute && class_attribute.value !== true) {
492+
const chunks = class_attribute.value;
493+
494+
if (chunks.length === 1 && chunks[0].type === 'Text') {
495+
chunks[0].data += ` ${analysis.css.hash}`;
496+
} else {
497+
chunks.push({
498+
type: 'Text',
499+
data: ` ${analysis.css.hash}`,
500+
raw: ` ${analysis.css.hash}`,
501+
start: -1,
502+
end: -1,
503+
parent: null
504+
});
505+
}
506+
} else {
507+
element.attributes.push(
508+
create_attribute('class', -1, -1, [
509+
{
510+
type: 'Text',
511+
data: analysis.css.hash,
512+
raw: analysis.css.hash,
513+
parent: null,
514+
start: -1,
515+
end: -1
516+
}
517+
])
518+
);
519+
}
520+
}
521+
}
469522
}
470523

471524
// TODO

packages/svelte/src/compiler/phases/3-transform/index.js

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -25,64 +25,6 @@ export function transform_component(analysis, source, options) {
2525
};
2626
}
2727

28-
const css =
29-
analysis.css.ast && !analysis.inject_styles
30-
? render_stylesheet(source, analysis, options)
31-
: null;
32-
33-
outer: for (const element of analysis.elements) {
34-
if (element.metadata.scoped) {
35-
// Dynamic elements in dom mode always use spread for attributes and therefore shouldn't have a class attribute added to them
36-
// TODO this happens during the analysis phase, which shouldn't know anything about client vs server
37-
if (element.type === 'SvelteElement' && options.generate === 'client') continue;
38-
39-
/** @type {import('#compiler').Attribute | undefined} */
40-
let class_attribute = undefined;
41-
42-
for (const attribute of element.attributes) {
43-
if (attribute.type === 'SpreadAttribute') {
44-
// The spread method appends the hash to the end of the class attribute on its own
45-
continue outer;
46-
}
47-
48-
if (attribute.type !== 'Attribute') continue;
49-
if (attribute.name.toLowerCase() !== 'class') continue;
50-
51-
class_attribute = attribute;
52-
}
53-
54-
if (class_attribute && class_attribute.value !== true) {
55-
const chunks = class_attribute.value;
56-
57-
if (chunks.length === 1 && chunks[0].type === 'Text') {
58-
chunks[0].data += ` ${analysis.css.hash}`;
59-
} else {
60-
chunks.push({
61-
type: 'Text',
62-
data: ` ${analysis.css.hash}`,
63-
raw: ` ${analysis.css.hash}`,
64-
start: -1,
65-
end: -1,
66-
parent: null
67-
});
68-
}
69-
} else {
70-
element.attributes.push(
71-
create_attribute('class', -1, -1, [
72-
{
73-
type: 'Text',
74-
data: analysis.css.hash,
75-
raw: analysis.css.hash,
76-
parent: null,
77-
start: -1,
78-
end: -1
79-
}
80-
])
81-
);
82-
}
83-
}
84-
}
85-
8628
const program =
8729
options.generate === 'server'
8830
? server_component(analysis, options)
@@ -110,6 +52,11 @@ export function transform_component(analysis, source, options) {
11052
});
11153
merge_with_preprocessor_map(js, options, js_source_name);
11254

55+
const css =
56+
analysis.css.ast && !analysis.inject_styles
57+
? render_stylesheet(source, analysis, options)
58+
: null;
59+
11360
return {
11461
js,
11562
css,

0 commit comments

Comments
 (0)