mirror of https://github.com/sveltejs/svelte
parent
e7d324f305
commit
b8705a5b0c
@ -1,3 +1,3 @@
|
||||
export default {
|
||||
export default function visitComment () {
|
||||
// do nothing
|
||||
};
|
||||
}
|
||||
|
@ -1,22 +1,20 @@
|
||||
import deindent from '../../../utils/deindent.js';
|
||||
import findBlock from '../utils/findBlock.js';
|
||||
|
||||
export default {
|
||||
enter ( generator, node ) {
|
||||
const name = generator.current.getUniqueName( 'text' );
|
||||
export default function visitMustacheTag ( generator, node ) {
|
||||
const name = generator.current.getUniqueName( 'text' );
|
||||
|
||||
const { snippet } = generator.contextualise( node.expression );
|
||||
const { snippet } = generator.contextualise( node.expression );
|
||||
|
||||
generator.current.builders.init.addLine( `var last_${name} = ${snippet};` );
|
||||
generator.addElement( name, `${generator.helper( 'createText' )}( last_${name} )`, true );
|
||||
generator.current.builders.init.addLine( `var last_${name} = ${snippet};` );
|
||||
generator.addElement( name, `${generator.helper( 'createText' )}( last_${name} )`, true );
|
||||
|
||||
const fragment = findBlock( generator.current );
|
||||
if ( !fragment.tmp ) fragment.tmp = fragment.getUniqueName( 'tmp' );
|
||||
const fragment = findBlock( generator.current );
|
||||
if ( !fragment.tmp ) fragment.tmp = fragment.getUniqueName( 'tmp' );
|
||||
|
||||
generator.current.builders.update.addBlock( deindent`
|
||||
if ( ( ${fragment.tmp} = ${snippet} ) !== last_${name} ) {
|
||||
${name}.data = last_${name} = ${fragment.tmp};
|
||||
}
|
||||
` );
|
||||
}
|
||||
};
|
||||
generator.current.builders.update.addBlock( deindent`
|
||||
if ( ( ${fragment.tmp} = ${snippet} ) !== last_${name} ) {
|
||||
${name}.data = last_${name} = ${fragment.tmp};
|
||||
}
|
||||
` );
|
||||
}
|
@ -1,43 +1,41 @@
|
||||
import deindent from '../../../utils/deindent.js';
|
||||
import findBlock from '../utils/findBlock.js';
|
||||
|
||||
export default {
|
||||
enter ( generator, node ) {
|
||||
const name = generator.current.getUniqueName( 'raw' );
|
||||
export default function visitRawMustacheTag ( generator, node ) {
|
||||
const name = generator.current.getUniqueName( 'raw' );
|
||||
|
||||
const { snippet } = generator.contextualise( node.expression );
|
||||
const { snippet } = generator.contextualise( node.expression );
|
||||
|
||||
// we would have used comments here, but the `insertAdjacentHTML` api only
|
||||
// exists for `Element`s.
|
||||
const before = `${name}_before`;
|
||||
generator.addElement( before, `${generator.helper( 'createElement' )}( 'noscript' )`, true );
|
||||
// we would have used comments here, but the `insertAdjacentHTML` api only
|
||||
// exists for `Element`s.
|
||||
const before = `${name}_before`;
|
||||
generator.addElement( before, `${generator.helper( 'createElement' )}( 'noscript' )`, true );
|
||||
|
||||
const after = `${name}_after`;
|
||||
generator.addElement( after, `${generator.helper( 'createElement' )}( 'noscript' )`, true );
|
||||
const after = `${name}_after`;
|
||||
generator.addElement( after, `${generator.helper( 'createElement' )}( 'noscript' )`, true );
|
||||
|
||||
const isToplevel = generator.current.localElementDepth === 0;
|
||||
const isToplevel = generator.current.localElementDepth === 0;
|
||||
|
||||
generator.current.builders.init.addLine( `var last_${name} = ${snippet};` );
|
||||
const mountStatement = `${before}.insertAdjacentHTML( 'afterend', last_${name} );`;
|
||||
const detachStatement = `${generator.helper( 'detachBetween' )}( ${before}, ${after} );`;
|
||||
generator.current.builders.init.addLine( `var last_${name} = ${snippet};` );
|
||||
const mountStatement = `${before}.insertAdjacentHTML( 'afterend', last_${name} );`;
|
||||
const detachStatement = `${generator.helper( 'detachBetween' )}( ${before}, ${after} );`;
|
||||
|
||||
if ( isToplevel ) {
|
||||
generator.current.builders.mount.addLine( mountStatement );
|
||||
} else {
|
||||
generator.current.builders.init.addLine( mountStatement );
|
||||
}
|
||||
if ( isToplevel ) {
|
||||
generator.current.builders.mount.addLine( mountStatement );
|
||||
} else {
|
||||
generator.current.builders.init.addLine( mountStatement );
|
||||
}
|
||||
|
||||
const fragment = findBlock( generator.current );
|
||||
if ( !fragment.tmp ) fragment.tmp = fragment.getUniqueName( 'tmp' );
|
||||
const fragment = findBlock( generator.current );
|
||||
if ( !fragment.tmp ) fragment.tmp = fragment.getUniqueName( 'tmp' );
|
||||
|
||||
generator.current.builders.update.addBlock( deindent`
|
||||
if ( ( ${fragment.tmp} = ${snippet} ) !== last_${name} ) {
|
||||
last_${name} = ${fragment.tmp};
|
||||
${detachStatement}
|
||||
${mountStatement}
|
||||
}
|
||||
` );
|
||||
generator.current.builders.update.addBlock( deindent`
|
||||
if ( ( ${fragment.tmp} = ${snippet} ) !== last_${name} ) {
|
||||
last_${name} = ${fragment.tmp};
|
||||
${detachStatement}
|
||||
${mountStatement}
|
||||
}
|
||||
` );
|
||||
|
||||
generator.current.builders.detachRaw.addBlock( detachStatement );
|
||||
}
|
||||
};
|
||||
generator.current.builders.detachRaw.addBlock( detachStatement );
|
||||
}
|
@ -1,10 +1,8 @@
|
||||
export default {
|
||||
enter ( generator, node ) {
|
||||
if ( generator.current.namespace && !/\S/.test( node.data ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const name = generator.current.getUniqueName( `text` );
|
||||
generator.addElement( name, `${generator.helper( 'createText' )}( ${JSON.stringify( node.data )} )`, false );
|
||||
export default function visitText ( generator, node ) {
|
||||
if ( generator.current.namespace && !/\S/.test( node.data ) ) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
const name = generator.current.getUniqueName( `text` );
|
||||
generator.addElement( name, `${generator.helper( 'createText' )}( ${JSON.stringify( node.data )} )`, false );
|
||||
}
|
@ -1,14 +1,12 @@
|
||||
export default {
|
||||
enter ( generator ) {
|
||||
const anchor = `yield_anchor`;
|
||||
generator.createAnchor( anchor );
|
||||
export default function visitYieldTag ( generator ) {
|
||||
const anchor = `yield_anchor`;
|
||||
generator.createAnchor( anchor );
|
||||
|
||||
generator.current.builders.mount.addLine(
|
||||
`${generator.current.component}._yield && ${generator.current.component}._yield.mount( ${generator.current.target}, ${anchor} );`
|
||||
);
|
||||
generator.current.builders.mount.addLine(
|
||||
`${generator.current.component}._yield && ${generator.current.component}._yield.mount( ${generator.current.target}, ${anchor} );`
|
||||
);
|
||||
|
||||
generator.current.builders.teardown.addLine(
|
||||
`${generator.current.component}._yield && ${generator.current.component}._yield.teardown( detach );`
|
||||
);
|
||||
}
|
||||
};
|
||||
generator.current.builders.teardown.addLine(
|
||||
`${generator.current.component}._yield && ${generator.current.component}._yield.teardown( detach );`
|
||||
);
|
||||
}
|
Loading…
Reference in new issue