|
|
|
@ -217,106 +217,121 @@ export default class Component {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
generate(result: string) {
|
|
|
|
|
const { compileOptions, name } = this;
|
|
|
|
|
const { format = 'esm' } = compileOptions;
|
|
|
|
|
let js = null;
|
|
|
|
|
let css = null;
|
|
|
|
|
|
|
|
|
|
const banner = `/* ${this.file ? `${this.file} ` : ``}generated by Svelte v${"__VERSION__"} */`;
|
|
|
|
|
if (result) {
|
|
|
|
|
const { compileOptions, name } = this;
|
|
|
|
|
const { format = 'esm' } = compileOptions;
|
|
|
|
|
|
|
|
|
|
// TODO use same regex for both
|
|
|
|
|
result = result.replace(compileOptions.generate === 'ssr' ? /(@+|#+)(\w*(?:-\w*)?)/g : /(@+)(\w*(?:-\w*)?)/g, (match: string, sigil: string, name: string) => {
|
|
|
|
|
if (sigil === '@') {
|
|
|
|
|
if (internal_exports.has(name)) {
|
|
|
|
|
if (compileOptions.dev && internal_exports.has(`${name}Dev`)) name = `${name}Dev`;
|
|
|
|
|
this.helpers.add(name);
|
|
|
|
|
}
|
|
|
|
|
const banner = `/* ${this.file ? `${this.file} ` : ``}generated by Svelte v${"__VERSION__"} */`;
|
|
|
|
|
|
|
|
|
|
return this.alias(name);
|
|
|
|
|
}
|
|
|
|
|
// TODO use same regex for both
|
|
|
|
|
result = result.replace(compileOptions.generate === 'ssr' ? /(@+|#+)(\w*(?:-\w*)?)/g : /(@+)(\w*(?:-\w*)?)/g, (match: string, sigil: string, name: string) => {
|
|
|
|
|
if (sigil === '@') {
|
|
|
|
|
if (internal_exports.has(name)) {
|
|
|
|
|
if (compileOptions.dev && internal_exports.has(`${name}Dev`)) name = `${name}Dev`;
|
|
|
|
|
this.helpers.add(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sigil.slice(1) + name;
|
|
|
|
|
});
|
|
|
|
|
return this.alias(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const importedHelpers = Array.from(this.helpers)
|
|
|
|
|
.sort()
|
|
|
|
|
.map(name => {
|
|
|
|
|
const alias = this.alias(name);
|
|
|
|
|
return { name, alias };
|
|
|
|
|
return sigil.slice(1) + name;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const module = wrapModule(
|
|
|
|
|
result,
|
|
|
|
|
format,
|
|
|
|
|
name,
|
|
|
|
|
compileOptions,
|
|
|
|
|
banner,
|
|
|
|
|
compileOptions.sveltePath,
|
|
|
|
|
importedHelpers,
|
|
|
|
|
this.imports,
|
|
|
|
|
this.vars.filter(variable => variable.module && variable.export_name).map(variable => ({
|
|
|
|
|
name: variable.name,
|
|
|
|
|
as: variable.export_name
|
|
|
|
|
})),
|
|
|
|
|
this.source
|
|
|
|
|
);
|
|
|
|
|
const importedHelpers = Array.from(this.helpers)
|
|
|
|
|
.sort()
|
|
|
|
|
.map(name => {
|
|
|
|
|
const alias = this.alias(name);
|
|
|
|
|
return { name, alias };
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const parts = module.split('✂]');
|
|
|
|
|
const finalChunk = parts.pop();
|
|
|
|
|
const module = wrapModule(
|
|
|
|
|
result,
|
|
|
|
|
format,
|
|
|
|
|
name,
|
|
|
|
|
compileOptions,
|
|
|
|
|
banner,
|
|
|
|
|
compileOptions.sveltePath,
|
|
|
|
|
importedHelpers,
|
|
|
|
|
this.imports,
|
|
|
|
|
this.vars.filter(variable => variable.module && variable.export_name).map(variable => ({
|
|
|
|
|
name: variable.name,
|
|
|
|
|
as: variable.export_name
|
|
|
|
|
})),
|
|
|
|
|
this.source
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const compiled = new Bundle({ separator: '' });
|
|
|
|
|
const parts = module.split('✂]');
|
|
|
|
|
const finalChunk = parts.pop();
|
|
|
|
|
|
|
|
|
|
function addString(str: string) {
|
|
|
|
|
compiled.addSource({
|
|
|
|
|
content: new MagicString(str),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
const compiled = new Bundle({ separator: '' });
|
|
|
|
|
|
|
|
|
|
const { filename } = compileOptions;
|
|
|
|
|
function addString(str: string) {
|
|
|
|
|
compiled.addSource({
|
|
|
|
|
content: new MagicString(str),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// special case — the source file doesn't actually get used anywhere. we need
|
|
|
|
|
// to add an empty file to populate map.sources and map.sourcesContent
|
|
|
|
|
if (!parts.length) {
|
|
|
|
|
compiled.addSource({
|
|
|
|
|
filename,
|
|
|
|
|
content: new MagicString(this.source).remove(0, this.source.length),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
const { filename } = compileOptions;
|
|
|
|
|
|
|
|
|
|
// special case — the source file doesn't actually get used anywhere. we need
|
|
|
|
|
// to add an empty file to populate map.sources and map.sourcesContent
|
|
|
|
|
if (!parts.length) {
|
|
|
|
|
compiled.addSource({
|
|
|
|
|
filename,
|
|
|
|
|
content: new MagicString(this.source).remove(0, this.source.length),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const pattern = /\[✂(\d+)-(\d+)$/;
|
|
|
|
|
const pattern = /\[✂(\d+)-(\d+)$/;
|
|
|
|
|
|
|
|
|
|
parts.forEach((str: string) => {
|
|
|
|
|
const chunk = str.replace(pattern, '');
|
|
|
|
|
if (chunk) addString(chunk);
|
|
|
|
|
parts.forEach((str: string) => {
|
|
|
|
|
const chunk = str.replace(pattern, '');
|
|
|
|
|
if (chunk) addString(chunk);
|
|
|
|
|
|
|
|
|
|
const match = pattern.exec(str);
|
|
|
|
|
const match = pattern.exec(str);
|
|
|
|
|
|
|
|
|
|
const snippet = this.code.snip(+match[1], +match[2]);
|
|
|
|
|
const snippet = this.code.snip(+match[1], +match[2]);
|
|
|
|
|
|
|
|
|
|
compiled.addSource({
|
|
|
|
|
filename,
|
|
|
|
|
content: snippet,
|
|
|
|
|
compiled.addSource({
|
|
|
|
|
filename,
|
|
|
|
|
content: snippet,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
addString(finalChunk);
|
|
|
|
|
addString(finalChunk);
|
|
|
|
|
|
|
|
|
|
const css = compileOptions.customElement ?
|
|
|
|
|
{ code: null, map: null } :
|
|
|
|
|
this.stylesheet.render(compileOptions.cssOutputFilename, true);
|
|
|
|
|
css = compileOptions.customElement ?
|
|
|
|
|
{ code: null, map: null } :
|
|
|
|
|
this.stylesheet.render(compileOptions.cssOutputFilename, true);
|
|
|
|
|
|
|
|
|
|
const js = {
|
|
|
|
|
code: compiled.toString(),
|
|
|
|
|
map: compiled.generateMap({
|
|
|
|
|
includeContent: true,
|
|
|
|
|
file: compileOptions.outputFilename,
|
|
|
|
|
})
|
|
|
|
|
};
|
|
|
|
|
js = {
|
|
|
|
|
code: compiled.toString(),
|
|
|
|
|
map: compiled.generateMap({
|
|
|
|
|
includeContent: true,
|
|
|
|
|
file: compileOptions.outputFilename,
|
|
|
|
|
})
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
js,
|
|
|
|
|
css,
|
|
|
|
|
ast: this.ast,
|
|
|
|
|
warnings: this.warnings,
|
|
|
|
|
stats: this.stats.render(this)
|
|
|
|
|
vars: this.vars.filter(v => !v.global && !v.implicit && !v.internal).map(v => ({
|
|
|
|
|
name: v.name,
|
|
|
|
|
export_name: v.export_name || null,
|
|
|
|
|
injected: v.injected || false,
|
|
|
|
|
module: v.module || false,
|
|
|
|
|
mutated: v.mutated || false,
|
|
|
|
|
reassigned: v.reassigned || false,
|
|
|
|
|
referenced: v.referenced || false,
|
|
|
|
|
writable: v.writable || false
|
|
|
|
|
})),
|
|
|
|
|
stats: this.stats.render()
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|