Skip to content
This repository

Add type checks on parameters #4

Open
wants to merge 1 commit into from

2 participants

Forbes Lindesay Don't Add Me To Your Organization a.k.a The Travis Bot
Forbes Lindesay

Throwing errors when incorrect arguments are passed to update and source would make it much easier to work out what's going wrong when people make mistakes calling this library.

Forbes Lindesay ForbesLindesay Add type checks on parameters
Throwing errors when incorrect arguments are passed to update and source would make it much easier to work out what's going wrong when people make mistakes calling this library.
2fbe819
Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 2fbe819 into 7c06835).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Aug 14, 2012
Forbes Lindesay ForbesLindesay Add type checks on parameters
Throwing errors when incorrect arguments are passed to update and source would make it much easier to work out what's going wrong when people make mistakes calling this library.
2fbe819
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 7 additions and 0 deletions. Show diff stats Hide diff stats

  1. +7 0 index.js
7 index.js
@@ -50,6 +50,7 @@ function insertHelpers (node, parent, chunks) {
50 50 node.parent = parent;
51 51
52 52 node.source = function () {
  53 + if (arguments.length !== 0) throw new Error('Source doesn\'t take any arguments, perhaps you meant update?');
53 54 return chunks.slice(
54 55 node.range[0], node.range[1] + 1
55 56 ).join('');
@@ -67,6 +68,12 @@ function insertHelpers (node, parent, chunks) {
67 68 }
68 69
69 70 function update (s) {
  71 + if (arguments.length !== 1) {
  72 + throw new Error('Update takes exactly one argument of type string and you passed ' + arguments.length + '.');
  73 + }
  74 + if (typeof s !== 'string') {
  75 + throw new Error('The argument to update must be of type string, you passed an argument of type ' + typeof s + '.')
  76 + }
70 77 chunks[node.range[0]] = s;
71 78 for (var i = node.range[0] + 1; i < node.range[1] + 1; i++) {
72 79 chunks[i] = '';

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.