|
|
|
@ -302,9 +302,15 @@ export default function dom ( parsed, source, options, names ) {
|
|
|
|
|
builders.main.addBlock( `${name}.prototype = template.methods;` );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const standalone = options.standalone !== false;
|
|
|
|
|
const sharedPath = options.shared === true ? 'svelte/shared.js' : options.shared;
|
|
|
|
|
|
|
|
|
|
builders.main.addBlock( standalone ?
|
|
|
|
|
builders.main.addBlock( sharedPath ?
|
|
|
|
|
deindent`
|
|
|
|
|
${name}.prototype.get = get;
|
|
|
|
|
${name}.prototype.fire = fire;
|
|
|
|
|
${name}.prototype.observe = observe;
|
|
|
|
|
${name}.prototype.on = on;
|
|
|
|
|
` :
|
|
|
|
|
deindent`
|
|
|
|
|
${name}.prototype.get = ${shared.get};
|
|
|
|
|
|
|
|
|
@ -313,12 +319,6 @@ export default function dom ( parsed, source, options, names ) {
|
|
|
|
|
${name}.prototype.observe = ${shared.observe};
|
|
|
|
|
|
|
|
|
|
${name}.prototype.on = ${shared.on};
|
|
|
|
|
` :
|
|
|
|
|
deindent`
|
|
|
|
|
${name}.prototype.get = get;
|
|
|
|
|
${name}.prototype.fire = fire;
|
|
|
|
|
${name}.prototype.observe = observe;
|
|
|
|
|
${name}.prototype.on = on;
|
|
|
|
|
` );
|
|
|
|
|
|
|
|
|
|
builders.main.addBlock( deindent`
|
|
|
|
@ -336,22 +336,22 @@ export default function dom ( parsed, source, options, names ) {
|
|
|
|
|
};
|
|
|
|
|
` );
|
|
|
|
|
|
|
|
|
|
if ( standalone ) {
|
|
|
|
|
builders.main.addBlock( shared.dispatchObservers.toString() );
|
|
|
|
|
|
|
|
|
|
Object.keys( generator.uses ).forEach( key => {
|
|
|
|
|
const fn = shared[ key ]; // eslint-disable-line import/namespace
|
|
|
|
|
builders.main.addBlock( fn.toString() );
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
if ( sharedPath ) {
|
|
|
|
|
if ( format !== 'es' ) {
|
|
|
|
|
throw new Error( `Non-standalone components must be compiled to ES2015 modules (format: 'es')` );
|
|
|
|
|
throw new Error( `Components with shared helpers must be compiled to ES2015 modules (format: 'es')` );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const names = [ 'get', 'fire', 'observe', 'on', 'dispatchObservers' ].concat( Object.keys( generator.uses ) );
|
|
|
|
|
builders.main.addLineAtStart(
|
|
|
|
|
`import { ${names.join( ', ' )} } from 'svelte/shared.js'`
|
|
|
|
|
`import { ${names.join( ', ' )} } from '${sharedPath}'`
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
builders.main.addBlock( shared.dispatchObservers.toString() );
|
|
|
|
|
|
|
|
|
|
Object.keys( generator.uses ).forEach( key => {
|
|
|
|
|
const fn = shared[ key ]; // eslint-disable-line import/namespace
|
|
|
|
|
builders.main.addBlock( fn.toString() );
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return generator.generate( builders.main.toString(), options, { name, format } );
|
|
|
|
|