|
|
@ -6,10 +6,11 @@ import processCss from '../shared/processCss.js';
|
|
|
|
import visitors from './visitors/index.js';
|
|
|
|
import visitors from './visitors/index.js';
|
|
|
|
import Generator from '../Generator.js';
|
|
|
|
import Generator from '../Generator.js';
|
|
|
|
import * as shared from '../../shared/index.js';
|
|
|
|
import * as shared from '../../shared/index.js';
|
|
|
|
|
|
|
|
import devHelperLookup from './utils/devHelperLookup.js';
|
|
|
|
|
|
|
|
|
|
|
|
class DomGenerator extends Generator {
|
|
|
|
class DomGenerator extends Generator {
|
|
|
|
constructor ( parsed, source, name, names, visitors ) {
|
|
|
|
constructor ( parsed, source, name, names, visitors, options ) {
|
|
|
|
super( parsed, source, name, names, visitors );
|
|
|
|
super( parsed, source, name, names, visitors, options );
|
|
|
|
this.renderers = [];
|
|
|
|
this.renderers = [];
|
|
|
|
this.uses = {};
|
|
|
|
this.uses = {};
|
|
|
|
|
|
|
|
|
|
|
@ -132,6 +133,9 @@ class DomGenerator extends Generator {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
helper ( name ) {
|
|
|
|
helper ( name ) {
|
|
|
|
|
|
|
|
if ( this.options.dev && devHelperLookup[ name ] ) {
|
|
|
|
|
|
|
|
name = devHelperLookup[ name ];
|
|
|
|
|
|
|
|
}
|
|
|
|
this.uses[ name ] = true;
|
|
|
|
this.uses[ name ] = true;
|
|
|
|
|
|
|
|
|
|
|
|
if ( !( name in this.aliases ) ) {
|
|
|
|
if ( !( name in this.aliases ) ) {
|
|
|
@ -152,7 +156,7 @@ export default function dom ( parsed, source, options, names ) {
|
|
|
|
const format = options.format || 'es';
|
|
|
|
const format = options.format || 'es';
|
|
|
|
const name = options.name || 'SvelteComponent';
|
|
|
|
const name = options.name || 'SvelteComponent';
|
|
|
|
|
|
|
|
|
|
|
|
const generator = new DomGenerator( parsed, source, name, names, visitors );
|
|
|
|
const generator = new DomGenerator( parsed, source, name, names, visitors, options );
|
|
|
|
|
|
|
|
|
|
|
|
const { computations, templateProperties } = generator.parseJs();
|
|
|
|
const { computations, templateProperties } = generator.parseJs();
|
|
|
|
|
|
|
|
|
|
|
@ -362,28 +366,14 @@ export default function dom ( parsed, source, options, names ) {
|
|
|
|
|
|
|
|
|
|
|
|
const sharedPath = options.shared === true ? 'svelte/shared.js' : options.shared;
|
|
|
|
const sharedPath = options.shared === true ? 'svelte/shared.js' : options.shared;
|
|
|
|
|
|
|
|
|
|
|
|
builders.main.addBlock( sharedPath ?
|
|
|
|
[ 'get', 'fire', 'observe', 'on', 'set', '_flush' ].forEach( methodName => {
|
|
|
|
deindent`
|
|
|
|
if ( sharedPath ) {
|
|
|
|
${name}.prototype.get = ${generator.helper( 'get' )};
|
|
|
|
builders.main.addLine( `${name}.prototype.${methodName} = ${generator.helper( methodName )};` );
|
|
|
|
${name}.prototype.fire = ${generator.helper( 'fire' )};
|
|
|
|
} else {
|
|
|
|
${name}.prototype.observe = ${generator.helper( 'observe' )};
|
|
|
|
const fn = shared[ options.dev && devHelperLookup[ methodName ] ? devHelperLookup[ methodName ] : methodName ]; // eslint-disable-line import/namespace
|
|
|
|
${name}.prototype.on = ${generator.helper( 'on' )};
|
|
|
|
builders.main.addLine( `${name}.prototype.${methodName} = ${fn};` );
|
|
|
|
${name}.prototype.set = ${generator.helper( 'set' )};
|
|
|
|
}
|
|
|
|
${name}.prototype._flush = ${generator.helper( '_flush' )};
|
|
|
|
});
|
|
|
|
` :
|
|
|
|
|
|
|
|
deindent`
|
|
|
|
|
|
|
|
${name}.prototype.get = ${shared.get};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
${name}.prototype.fire = ${shared.fire};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
${name}.prototype.observe = ${shared.observe};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
${name}.prototype.on = ${shared.on};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
${name}.prototype.set = ${shared.set};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
${name}.prototype._flush = ${shared._flush};
|
|
|
|
|
|
|
|
` );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO deprecate component.teardown()
|
|
|
|
// TODO deprecate component.teardown()
|
|
|
|
builders.main.addBlock( deindent`
|
|
|
|
builders.main.addBlock( deindent`
|
|
|
@ -417,11 +407,7 @@ export default function dom ( parsed, source, options, names ) {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Object.keys( generator.uses ).forEach( key => {
|
|
|
|
Object.keys( generator.uses ).forEach( key => {
|
|
|
|
const fn = shared[ key ]; // eslint-disable-line import/namespace
|
|
|
|
const fn = shared[ key ]; // eslint-disable-line import/namespace
|
|
|
|
if ( key !== generator.aliases[ key ] ) {
|
|
|
|
builders.main.addBlock( fn.toString().replace( /^function [^(]*/, 'function ' + generator.aliases[ key ] ) );
|
|
|
|
builders.main.addBlock( `var ${generator.aliases[ key ]} = ${fn.toString()}}` );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
builders.main.addBlock( fn.toString() );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|