revert some stuff

pull/10502/head
Rich Harris 3 years ago
parent 7c9b11d3ea
commit 25568672c0

@ -466,6 +466,59 @@ export function analyze_component(root, options) {
for (const element of analysis.elements) { for (const element of analysis.elements) {
prune(analysis.css.ast, element); prune(analysis.css.ast, element);
} }
outer: for (const element of analysis.elements) {
if (element.metadata.scoped) {
// Dynamic elements in dom mode always use spread for attributes and therefore shouldn't have a class attribute added to them
// TODO this happens during the analysis phase, which shouldn't know anything about client vs server
if (element.type === 'SvelteElement' && options.generate === 'client') continue;
/** @type {import('#compiler').Attribute | undefined} */
let class_attribute = undefined;
for (const attribute of element.attributes) {
if (attribute.type === 'SpreadAttribute') {
// The spread method appends the hash to the end of the class attribute on its own
continue outer;
}
if (attribute.type !== 'Attribute') continue;
if (attribute.name.toLowerCase() !== 'class') continue;
class_attribute = attribute;
}
if (class_attribute && class_attribute.value !== true) {
const chunks = class_attribute.value;
if (chunks.length === 1 && chunks[0].type === 'Text') {
chunks[0].data += ` ${analysis.css.hash}`;
} else {
chunks.push({
type: 'Text',
data: ` ${analysis.css.hash}`,
raw: ` ${analysis.css.hash}`,
start: -1,
end: -1,
parent: null
});
}
} else {
element.attributes.push(
create_attribute('class', -1, -1, [
{
type: 'Text',
data: analysis.css.hash,
raw: analysis.css.hash,
parent: null,
start: -1,
end: -1
}
])
);
}
}
}
} }
// TODO // TODO

@ -25,64 +25,6 @@ export function transform_component(analysis, source, options) {
}; };
} }
const css =
analysis.css.ast && !analysis.inject_styles
? render_stylesheet(source, analysis, options)
: null;
outer: for (const element of analysis.elements) {
if (element.metadata.scoped) {
// Dynamic elements in dom mode always use spread for attributes and therefore shouldn't have a class attribute added to them
// TODO this happens during the analysis phase, which shouldn't know anything about client vs server
if (element.type === 'SvelteElement' && options.generate === 'client') continue;
/** @type {import('#compiler').Attribute | undefined} */
let class_attribute = undefined;
for (const attribute of element.attributes) {
if (attribute.type === 'SpreadAttribute') {
// The spread method appends the hash to the end of the class attribute on its own
continue outer;
}
if (attribute.type !== 'Attribute') continue;
if (attribute.name.toLowerCase() !== 'class') continue;
class_attribute = attribute;
}
if (class_attribute && class_attribute.value !== true) {
const chunks = class_attribute.value;
if (chunks.length === 1 && chunks[0].type === 'Text') {
chunks[0].data += ` ${analysis.css.hash}`;
} else {
chunks.push({
type: 'Text',
data: ` ${analysis.css.hash}`,
raw: ` ${analysis.css.hash}`,
start: -1,
end: -1,
parent: null
});
}
} else {
element.attributes.push(
create_attribute('class', -1, -1, [
{
type: 'Text',
data: analysis.css.hash,
raw: analysis.css.hash,
parent: null,
start: -1,
end: -1
}
])
);
}
}
}
const program = const program =
options.generate === 'server' options.generate === 'server'
? server_component(analysis, options) ? server_component(analysis, options)
@ -110,6 +52,11 @@ export function transform_component(analysis, source, options) {
}); });
merge_with_preprocessor_map(js, options, js_source_name); merge_with_preprocessor_map(js, options, js_source_name);
const css =
analysis.css.ast && !analysis.inject_styles
? render_stylesheet(source, analysis, options)
: null;
return { return {
js, js,
css, css,

Loading…
Cancel
Save