mirror of
https://github.com/sveltejs/svelte.git
synced 2024-12-01 17:30:59 +01:00
mostly fix insane node 4 issue
This commit is contained in:
parent
e32e69f3e8
commit
be33a29a56
@ -119,8 +119,9 @@ class DomGenerator extends Generator {
|
||||
}
|
||||
}
|
||||
|
||||
generateBlock ( node, name ) {
|
||||
generateBlock ( node, name, type ) {
|
||||
this.push({
|
||||
type,
|
||||
name,
|
||||
target: 'target',
|
||||
localElementDepth: 0,
|
||||
@ -203,6 +204,7 @@ export default function dom ( parsed, source, options ) {
|
||||
const component = getUniqueName( 'component' );
|
||||
|
||||
generator.push({
|
||||
type: 'block',
|
||||
name: generator.alias( 'render_main_fragment' ),
|
||||
namespace,
|
||||
target: 'target',
|
||||
|
4
src/generators/dom/utils/findBlock.js
Normal file
4
src/generators/dom/utils/findBlock.js
Normal file
@ -0,0 +1,4 @@
|
||||
export default function findBlock ( fragment ) {
|
||||
while ( fragment.type !== 'block' ) fragment = fragment.parent;
|
||||
return fragment;
|
||||
}
|
@ -67,7 +67,7 @@ export default {
|
||||
const yieldName = generator.getUniqueName( `render_${name}_yield_fragment` );
|
||||
const params = current.params.join( ', ' );
|
||||
|
||||
generator.generateBlock( node, yieldName );
|
||||
generator.generateBlock( node, yieldName, 'yield' );
|
||||
|
||||
const yieldFragment = current.getUniqueName( `${name}_yield_fragment` );
|
||||
|
||||
@ -151,6 +151,7 @@ export default {
|
||||
if ( !local.update.isEmpty() ) current.builders.update.addBlock( local.update );
|
||||
|
||||
generator.push({
|
||||
type: 'component',
|
||||
namespace: local.namespace,
|
||||
target: name,
|
||||
parent: current,
|
||||
|
@ -168,7 +168,7 @@ export default {
|
||||
}
|
||||
|
||||
if ( node.else ) {
|
||||
generator.generateBlock( node.else, renderElse );
|
||||
generator.generateBlock( node.else, renderElse, 'block' );
|
||||
}
|
||||
|
||||
const indexNames = new Map( generator.current.indexNames );
|
||||
@ -193,6 +193,7 @@ export default {
|
||||
const getUniqueName = generator.getUniqueNameMaker( blockParams );
|
||||
|
||||
generator.push({
|
||||
type: 'block',
|
||||
name: renderer,
|
||||
target: 'target',
|
||||
expression: node.expression,
|
||||
|
@ -101,6 +101,7 @@ export default {
|
||||
generator.createMountStatement( name );
|
||||
|
||||
generator.push({
|
||||
type: 'element',
|
||||
namespace: local.namespace,
|
||||
target: name,
|
||||
parent: generator.current,
|
||||
|
@ -9,7 +9,7 @@ function getConditionsAndBlocks ( generator, node, _name, i = 0 ) {
|
||||
block: name
|
||||
}];
|
||||
|
||||
generator.generateBlock( node, name );
|
||||
generator.generateBlock( node, name, 'block' );
|
||||
|
||||
if ( node.else && node.else.children.length === 1 &&
|
||||
node.else.children[0].type === 'IfBlock' ) {
|
||||
@ -24,7 +24,7 @@ function getConditionsAndBlocks ( generator, node, _name, i = 0 ) {
|
||||
});
|
||||
|
||||
if ( node.else ) {
|
||||
generator.generateBlock( node.else, name );
|
||||
generator.generateBlock( node.else, name, 'block' );
|
||||
}
|
||||
}
|
||||
return conditionsAndBlocks;
|
||||
|
@ -1,4 +1,5 @@
|
||||
import deindent from '../../../utils/deindent.js';
|
||||
import findBlock from '../utils/findBlock.js';
|
||||
|
||||
export default {
|
||||
enter ( generator, node ) {
|
||||
@ -9,12 +10,12 @@ export default {
|
||||
generator.current.builders.init.addLine( `var last_${name} = ${snippet};` );
|
||||
generator.addElement( name, `${generator.helper( 'createText' )}( last_${name} )`, true );
|
||||
|
||||
if ( !generator.current.tmp ) {
|
||||
generator.current.tmp = generator.current.getUniqueName( 'tmp' );
|
||||
}
|
||||
const fragment = findBlock( generator.current );
|
||||
if ( !fragment.tmp ) fragment.tmp = fragment.getUniqueName( 'tmp' );
|
||||
|
||||
generator.current.builders.update.addBlock( deindent`
|
||||
if ( ( ${generator.current.tmp} = ${snippet} ) !== last_${name} ) {
|
||||
${name}.data = last_${name} = ${generator.current.tmp};
|
||||
if ( ( ${fragment.tmp} = ${snippet} ) !== last_${name} ) {
|
||||
${name}.data = last_${name} = ${fragment.tmp};
|
||||
}
|
||||
` );
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import deindent from '../../../utils/deindent.js';
|
||||
import findBlock from '../utils/findBlock.js';
|
||||
|
||||
export default {
|
||||
enter ( generator, node ) {
|
||||
@ -26,12 +27,12 @@ export default {
|
||||
generator.current.builders.init.addLine( mountStatement );
|
||||
}
|
||||
|
||||
if ( !generator.current.tmp ) {
|
||||
generator.current.tmp = generator.current.getUniqueName( 'tmp' );
|
||||
}
|
||||
const fragment = findBlock( generator.current );
|
||||
if ( !fragment.tmp ) fragment.tmp = fragment.getUniqueName( 'tmp' );
|
||||
|
||||
generator.current.builders.update.addBlock( deindent`
|
||||
if ( ( ${generator.current.tmp} = ${snippet} ) !== last_${name} ) {
|
||||
last_${name} = ${generator.current.tmp};
|
||||
if ( ( ${fragment.tmp} = ${snippet} ) !== last_${name} ) {
|
||||
last_${name} = ${fragment.tmp};
|
||||
${detachStatement}
|
||||
${mountStatement}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ import addElementBinding from './addElementBinding';
|
||||
import deindent from '../../../../utils/deindent.js';
|
||||
import flattenReference from '../../../../utils/flattenReference.js';
|
||||
import getStaticAttributeValue from './binding/getStaticAttributeValue.js';
|
||||
import findBlock from '../../utils/findBlock.js';
|
||||
|
||||
export default function addElementAttributes ( generator, node, local ) {
|
||||
node.attributes.forEach( attribute => {
|
||||
@ -105,12 +106,12 @@ export default function addElementAttributes ( generator, node, local ) {
|
||||
}
|
||||
|
||||
local.init.addLine( updater );
|
||||
if ( !generator.current.tmp ) {
|
||||
generator.current.tmp = generator.current.getUniqueName( 'tmp' );
|
||||
}
|
||||
const fragment = findBlock( generator.current );
|
||||
if ( !fragment.tmp ) fragment.tmp = fragment.getUniqueName( 'tmp' );
|
||||
|
||||
local.update.addBlock( deindent`
|
||||
if ( ( ${generator.current.tmp} = ${snippet} ) !== ${last} ) {
|
||||
${last} = ${generator.current.tmp};
|
||||
if ( ( ${fragment.tmp} = ${snippet} ) !== ${last} ) {
|
||||
${last} = ${fragment.tmp};
|
||||
${updater}
|
||||
}
|
||||
` );
|
||||
|
Loading…
Reference in New Issue
Block a user