Skip to content

Commit

Permalink
Merge pull request #343 from sveltejs/gh-342-typecheck-set-argument-i…
Browse files Browse the repository at this point in the history
…n-dev-mode

typecheck argument in _set when in dev mode
  • Loading branch information
Rich-Harris authored Mar 6, 2017
2 parents d8dbe4e + b2cc48b commit a463085
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/generators/dom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ export default function dom ( parsed, source, options, names ) {
_set: new CodeBuilder()
};

if ( options.dev ) {
builders._set.addBlock ( deindent`
if ( typeof newState !== 'object' ) {
throw new Error( 'Component .set was called without an object of data key-values to update.' );
}
`);
}

builders._set.addLine( 'var oldState = this._state;' );
builders._set.addLine( 'this._state = Object.assign( {}, oldState, newState );' );

Expand Down

0 comments on commit a463085

Please sign in to comment.