Skip to content

Commit cedd318

Browse files
authored
Merge pull request #565 from sveltejs/coverage
[WIP] increase test coverage
2 parents 3a7f7e2 + b342f2e commit cedd318

File tree

43 files changed

+2587
-103
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2587
-103
lines changed

mocha.coverage.opts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--require babel-register
22
--require reify
3-
--recursive
3+
--recursive
44
./**/__test__.js
55
test/*/index.js

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,12 @@
8080
},
8181
"nyc": {
8282
"include": [
83-
"src/**/*.js"
83+
"src/**/*.js",
84+
"shared.js"
8485
],
8586
"exclude": [
86-
"src/**/__test__.js"
87+
"src/**/__test__.js",
88+
"src/shared/**"
8789
]
8890
},
8991
"babel": {

src/generators/dom/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ export default function dom ( parsed, source, options ) {
183183
};
184184
185185
${name}.prototype.teardown = ${name}.prototype.destroy = function destroy ( detach ) {
186-
this.fire( 'destroy' );${templateProperties.ondestroy ? `\n${generator.alias( 'template' )}.ondestroy.call( this );` : ``}
186+
this.fire( 'destroy' );
187+
${templateProperties.ondestroy && `${generator.alias( 'template' )}.ondestroy.call( this );`}
187188
188189
this._fragment.destroy( detach !== false );
189190
this._fragment = null;

src/generators/dom/visitors/Element/meta/Window.js

-5
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ export default function visitWindow ( generator, block, node ) {
6060
}
6161

6262
if ( attribute.type === 'Binding' ) {
63-
if ( attribute.value.type !== 'Identifier' ) {
64-
const { parts, keypath } = flattenReference( attribute.value );
65-
throw new Error( `Bindings on <:Window/> must be to top-level properties, e.g. '${parts.pop()}' rather than '${keypath}'` );
66-
}
67-
6863
// in dev mode, throw if read-only values are written to
6964
if ( readonly.has( attribute.name ) ) {
7065
generator.readonly.add( attribute.value.name );

src/generators/dom/visitors/IfBlock.js

+26-27
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ function compoundWithOutros ( generator, block, state, node, branches, dynamic,
215215
const if_current_block_index = hasElse ? '' : `if ( ~${current_block_index} ) `;
216216

217217
block.addVariable( current_block_index );
218+
block.addVariable( name );
218219

219220
block.builders.create.addBlock( deindent`
220221
var ${if_block_creators} = [
@@ -233,12 +234,12 @@ function compoundWithOutros ( generator, block, state, node, branches, dynamic,
233234
if ( hasElse ) {
234235
block.builders.create.addBlock( deindent`
235236
${current_block_index} = ${get_block}( ${params} );
236-
${if_blocks}[ ${current_block_index} ] = ${if_block_creators}[ ${current_block_index} ]( ${params}, ${block.component} );
237+
${name} = ${if_blocks}[ ${current_block_index} ] = ${if_block_creators}[ ${current_block_index} ]( ${params}, ${block.component} );
237238
` );
238239
} else {
239240
block.builders.create.addBlock( deindent`
240241
if ( ~( ${current_block_index} = ${get_block}( ${params} ) ) ) {
241-
${if_blocks}[ ${current_block_index} ] = ${if_block_creators}[ ${current_block_index} ]( ${params}, ${block.component} );
242+
${name} = ${if_blocks}[ ${current_block_index} ] = ${if_block_creators}[ ${current_block_index} ]( ${params}, ${block.component} );
242243
}
243244
` );
244245
}
@@ -253,37 +254,35 @@ function compoundWithOutros ( generator, block, state, node, branches, dynamic,
253254

254255
const parentNode = state.parentNode || `${anchor}.parentNode`;
255256

256-
const changeBlock = deindent`
257-
var ${name} = ${if_blocks}[ ${previous_block_index} ];
258-
if ( ${name} ) {
259-
${name}.outro( function () {
260-
${if_blocks}[ ${previous_block_index} ].destroy( true );
261-
${if_blocks}[ ${previous_block_index} ] = null;
262-
});
263-
}
257+
const destroyOldBlock = deindent`
258+
${name}.outro( function () {
259+
${if_blocks}[ ${previous_block_index} ].destroy( true );
260+
${if_blocks}[ ${previous_block_index} ] = null;
261+
});
264262
`;
265263

266-
if ( hasElse ) {
267-
block.builders.create.addBlock( deindent`
268-
${name} = ${if_blocks}[ ${current_block_index} ];
269-
if ( !${name} ) {
270-
${name} = ${if_blocks}[ ${current_block_index} ] = ${if_block_creators}[ ${current_block_index} ]( ${params}, ${block.component} );
264+
const createNewBlock = deindent`
265+
${name} = ${if_blocks}[ ${current_block_index} ] = ${if_block_creators}[ ${current_block_index} ]( ${params}, ${block.component} );
266+
${name}.${mountOrIntro}( ${parentNode}, ${anchor} );
267+
`;
268+
269+
const changeBlock = hasElse ?
270+
deindent`
271+
${destroyOldBlock}
272+
273+
${createNewBlock}
274+
` :
275+
deindent`
276+
if ( ${name} ) {
277+
${destroyOldBlock}
271278
}
272279
273-
${name}.${mountOrIntro}( ${parentNode}, ${anchor} );
274-
` );
275-
} else {
276-
block.builders.create.addBlock( deindent`
277280
if ( ~${current_block_index} ) {
278-
${name} = ${if_blocks}[ ${current_block_index} ];
279-
if ( !${name} ) {
280-
${name} = ${if_blocks}[ ${current_block_index} ] = ${if_block_creators}[ ${current_block_index} ]( ${params}, ${block.component} );
281-
}
282-
283-
${name}.${mountOrIntro}( ${parentNode}, ${anchor} );
281+
${createNewBlock}
282+
} else {
283+
${name} = null;
284284
}
285-
` );
286-
}
285+
`;
287286

288287
if ( dynamic ) {
289288
block.builders.update.addBlock( deindent`

src/index.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,16 @@ export function create ( source, _options = {} ) {
5656
return;
5757
}
5858

59-
let result;
6059
try {
61-
result = (new Function( 'return ' + compiled.code ))();
60+
return (new Function( 'return ' + compiled.code ))();
6261
} catch ( err ) {
6362
if ( _options.onerror ) {
6463
_options.onerror( err );
64+
return;
6565
} else {
6666
throw err;
6767
}
68-
return;
6968
}
70-
71-
return result;
7269
}
7370

7471
export { parse, validate, version as VERSION };

0 commit comments

Comments
 (0)