rename template to source in generator, to avoid confusion

pull/31/head
Rich-Harris 8 years ago
parent 632a980948
commit 26a436fb87

@ -7,7 +7,7 @@ import flattenReference from './utils/flattenReference.js';
import visitors from './visitors/index.js'; import visitors from './visitors/index.js';
import processCss from './css/process.js'; import processCss from './css/process.js';
export default function generate ( parsed, template, options = {} ) { export default function generate ( parsed, source, options = {} ) {
const renderers = []; const renderers = [];
const generator = { const generator = {
@ -42,7 +42,7 @@ export default function generate ( parsed, template, options = {} ) {
}); });
}, },
code: new MagicString( template ), code: new MagicString( source ),
components: {}, components: {},
@ -100,7 +100,7 @@ export default function generate ( parsed, template, options = {} ) {
usesRefs: false, usesRefs: false,
template source
}; };
const templateProperties = {}; const templateProperties = {};
@ -120,9 +120,9 @@ export default function generate ( parsed, template, options = {} ) {
generator.code.overwrite( defaultExport.start, defaultExport.declaration.start, `var template = ` ); generator.code.overwrite( defaultExport.start, defaultExport.declaration.start, `var template = ` );
let i = defaultExport.start; let i = defaultExport.start;
while ( /\s/.test( template[ i - 1 ] ) ) i--; while ( /\s/.test( source[ i - 1 ] ) ) i--;
const indentation = template.slice( i, defaultExport.start ); const indentation = source.slice( i, defaultExport.start );
generator.code.insertLeft( finalNode.end, `\n\n${indentation}return template;` ); generator.code.insertLeft( finalNode.end, `\n\n${indentation}return template;` );
} }
@ -229,8 +229,6 @@ export default function generate ( parsed, template, options = {} ) {
dispatchObservers( observers.deferred, newState, oldState ); dispatchObservers( observers.deferred, newState, oldState );
` ); ` );
const addCss = parsed.css ? processCss( parsed ) : null;
const constructorName = options.name || 'SvelteComponent'; const constructorName = options.name || 'SvelteComponent';
const topLevelStatements = []; const topLevelStatements = [];
@ -369,7 +367,7 @@ export default function generate ( parsed, template, options = {} ) {
c = part.end; c = part.end;
}); });
generator.code.remove( c, template.length ); generator.code.remove( c, source.length );
generator.code.append( finalChunk ); generator.code.append( finalChunk );
sortedByResult.forEach( part => { sortedByResult.forEach( part => {

@ -10,7 +10,7 @@ export default {
const listName = `${name}_value`; const listName = `${name}_value`;
generator.current.initStatements.push( deindent` generator.current.initStatements.push( deindent`
var ${name}_anchor = document.createComment( ${JSON.stringify( `#each ${generator.template.slice( node.expression.start, node.expression.end )}` )} ); var ${name}_anchor = document.createComment( ${JSON.stringify( `#each ${generator.source.slice( node.expression.start, node.expression.end )}` )} );
${generator.current.target}.appendChild( ${name}_anchor ); ${generator.current.target}.appendChild( ${name}_anchor );
var ${name}_iterations = []; var ${name}_iterations = [];
const ${name}_fragment = document.createDocumentFragment(); const ${name}_fragment = document.createDocumentFragment();

@ -9,7 +9,7 @@ export default {
const renderer = `renderIfBlock_${i}`; const renderer = `renderIfBlock_${i}`;
generator.current.initStatements.push( deindent` generator.current.initStatements.push( deindent`
var ${name}_anchor = document.createComment( ${JSON.stringify( `#if ${generator.template.slice( node.expression.start, node.expression.end )}` )} ); var ${name}_anchor = document.createComment( ${JSON.stringify( `#if ${generator.source.slice( node.expression.start, node.expression.end )}` )} );
${generator.current.target}.appendChild( ${name}_anchor ); ${generator.current.target}.appendChild( ${name}_anchor );
var ${name} = null; var ${name} = null;
` ); ` );
@ -22,7 +22,7 @@ export default {
let expression; let expression;
if ( isReference( node.expression ) ) { if ( isReference( node.expression ) ) {
const reference = `${generator.template.slice( node.expression.start, node.expression.end )}`; const reference = `${generator.source.slice( node.expression.start, node.expression.end )}`;
expression = usedContexts[0] === 'root' ? `root.${reference}` : reference; expression = usedContexts[0] === 'root' ? `root.${reference}` : reference;
generator.current.updateStatements.push( deindent` generator.current.updateStatements.push( deindent`

@ -17,7 +17,7 @@ export default {
const snippet = `[✂${node.expression.start}-${node.expression.end}✂]`; const snippet = `[✂${node.expression.start}-${node.expression.end}✂]`;
if ( isReference( node.expression ) ) { if ( isReference( node.expression ) ) {
const reference = `${generator.template.slice( node.expression.start, node.expression.end )}`; const reference = `${generator.source.slice( node.expression.start, node.expression.end )}`;
const qualified = usedContexts[0] === 'root' ? `root.${reference}` : reference; const qualified = usedContexts[0] === 'root' ? `root.${reference}` : reference;
generator.current.updateStatements.push( deindent` generator.current.updateStatements.push( deindent`

Loading…
Cancel
Save