diff --git a/modules/angular2/src/change_detection/parser/lexer.ts b/modules/angular2/src/change_detection/parser/lexer.ts index 7162df61e5..0e99793d9a 100644 --- a/modules/angular2/src/change_detection/parser/lexer.ts +++ b/modules/angular2/src/change_detection/parser/lexer.ts @@ -17,7 +17,8 @@ enum TokenType { NUMBER } -@Injectable() export class Lexer { +@Injectable() +export class Lexer { tokenize(text: string): List { var scanner = new _Scanner(text); var tokens = []; diff --git a/modules/angular2/src/facade/lang.ts b/modules/angular2/src/facade/lang.ts index fade23d14f..6178ce9696 100644 --- a/modules/angular2/src/facade/lang.ts +++ b/modules/angular2/src/facade/lang.ts @@ -28,12 +28,11 @@ export function assertionsEnabled(): boolean { // TODO: remove calls to assert in production environment // Note: Can't just export this and import in in other files // as `assert` is a reserved keyword in Dart -_global.assert = - function assert(condition) { - if (assertionsEnabled_) { - _global['assert'].call(condition); - } - } +_global.assert = function assert(condition) { + if (assertionsEnabled_) { + _global['assert'].call(condition); + } +}; // This function is needed only to properly support Dart's const expressions // see https://github.com/angular/ts2dart/pull/151 for more info export function CONST_EXPR(expr: T): T { diff --git a/modules/angular2/src/http/enums.ts b/modules/angular2/src/http/enums.ts index 65bf3644f2..0a62a7803e 100644 --- a/modules/angular2/src/http/enums.ts +++ b/modules/angular2/src/http/enums.ts @@ -1,12 +1,47 @@ +export enum RequestModesOpts { + Cors, + NoCors, + SameOrigin +} -export enum RequestModesOpts {Cors, NoCors, SameOrigin}; +export enum RequestCacheOpts { + Default, + NoStore, + Reload, + NoCache, + ForceCache, + OnlyIfCached +} -export enum RequestCacheOpts {Default, NoStore, Reload, NoCache, ForceCache, OnlyIfCached}; +export enum RequestCredentialsOpts { + Omit, + SameOrigin, + Include +} -export enum RequestCredentialsOpts {Omit, SameOrigin, Include}; +export enum RequestMethods { + GET, + POST, + PUT, + DELETE, + OPTIONS, + HEAD, + PATCH +} -export enum RequestMethods {GET, POST, PUT, DELETE, OPTIONS, HEAD, PATCH}; +export enum ReadyStates { + UNSENT, + OPEN, + HEADERS_RECEIVED, + LOADING, + DONE, + CANCELLED +} -export enum ReadyStates {UNSENT, OPEN, HEADERS_RECEIVED, LOADING, DONE, CANCELLED}; - -export enum ResponseTypes {Basic, Cors, Default, Error, Opaque} +export enum ResponseTypes { + Basic, + Cors, + Default, + Error, + Opaque +} diff --git a/modules/angular2/src/test_lib/test_lib.ts b/modules/angular2/src/test_lib/test_lib.ts index dcb4e22398..5195806d3a 100644 --- a/modules/angular2/src/test_lib/test_lib.ts +++ b/modules/angular2/src/test_lib/test_lib.ts @@ -172,103 +172,97 @@ export function iit(name, fn) { // gives us bad error messages in tests. // The only way to do this in Jasmine is to monkey patch a method // to the object :-( -Map.prototype['jasmineToString'] = - function() { - var m = this; - if (!m) { - return '' + m; - } - var res = []; - m.forEach((v, k) => { res.push(`${k}:${v}`); }); - return `{ ${res.join(',')} }`; - } +Map.prototype['jasmineToString'] = function() { + var m = this; + if (!m) { + return '' + m; + } + var res = []; + m.forEach((v, k) => { res.push(`${k}:${v}`); }); + return `{ ${res.join(',')} }`; +}; - _global.beforeEach(function() { - jasmine.addMatchers({ - // Custom handler for Map as Jasmine does not support it yet - toEqual: function(util, customEqualityTesters) { - return { - compare: function(actual, expected) { - return {pass: util.equals(actual, expected, [compareMap])}; - } - }; +_global.beforeEach(function() { + jasmine.addMatchers({ + // Custom handler for Map as Jasmine does not support it yet + toEqual: function(util, customEqualityTesters) { + return { + compare: function(actual, expected) { + return {pass: util.equals(actual, expected, [compareMap])}; + } + }; - function compareMap(actual, expected) { - if (actual instanceof Map) { - var pass = actual.size === expected.size; - if (pass) { - actual.forEach((v, k) => { pass = pass && util.equals(v, expected.get(k)); }); - } - return pass; - } else { - return undefined; - } + function compareMap(actual, expected) { + if (actual instanceof Map) { + var pass = actual.size === expected.size; + if (pass) { + actual.forEach((v, k) => { pass = pass && util.equals(v, expected.get(k)); }); } - }, + return pass; + } else { + return undefined; + } + } + }, - toBePromise: function() { + toBePromise: function() { + return { + compare: function(actual, expectedClass) { + var pass = typeof actual === 'object' && typeof actual.then === 'function'; + return {pass: pass, get message() { return 'Expected ' + actual + ' to be a promise'; }}; + } + }; + }, + + toBeAnInstanceOf: function() { + return { + compare: function(actual, expectedClass) { + var pass = typeof actual === 'object' && actual instanceof expectedClass; return { - compare: function(actual, expectedClass) { - var pass = typeof actual === 'object' && typeof actual.then === 'function'; - return { - pass: pass, - get message() { return 'Expected ' + actual + ' to be a promise'; } - }; - } - }; - }, - - toBeAnInstanceOf: function() { - return { - compare: function(actual, expectedClass) { - var pass = typeof actual === 'object' && actual instanceof expectedClass; - return { - pass: pass, - get message() { - return 'Expected ' + actual + ' to be an instance of ' + expectedClass; - } - }; - } - }; - }, - - toHaveText: function() { - return { - compare: function(actual, expectedText) { - var actualText = elementText(actual); - return { - pass: actualText == expectedText, - get message() { - return 'Expected ' + actualText + ' to be equal to ' + expectedText; - } - }; - } - }; - }, - - toImplement: function() { - return { - compare: function(actualObject, expectedInterface) { - var objProps = Object.keys(actualObject.constructor.prototype); - var intProps = Object.keys(expectedInterface.prototype); - - var missedMethods = []; - intProps.forEach((k) => { - if (!actualObject.constructor.prototype[k]) missedMethods.push(k); - }); - - return { - pass: missedMethods.length == 0, - get message() { - return 'Expected ' + actualObject + ' to have the following methods: ' + - missedMethods.join(", "); - } - }; + pass: pass, + get message() { + return 'Expected ' + actual + ' to be an instance of ' + expectedClass; } }; } - }); - }); + }; + }, + + toHaveText: function() { + return { + compare: function(actual, expectedText) { + var actualText = elementText(actual); + return { + pass: actualText == expectedText, + get message() { return 'Expected ' + actualText + ' to be equal to ' + expectedText; } + }; + } + }; + }, + + toImplement: function() { + return { + compare: function(actualObject, expectedInterface) { + var objProps = Object.keys(actualObject.constructor.prototype); + var intProps = Object.keys(expectedInterface.prototype); + + var missedMethods = []; + intProps.forEach((k) => { + if (!actualObject.constructor.prototype[k]) missedMethods.push(k); + }); + + return { + pass: missedMethods.length == 0, + get message() { + return 'Expected ' + actualObject + ' to have the following methods: ' + + missedMethods.join(", "); + } + }; + } + }; + } + }); +}); export interface GuinessCompatibleSpy extends jasmine.Spy { /** By chaining the spy with and.returnValue, all calls to the function will return a specific diff --git a/modules/angular2/test/change_detection/change_detector_config.ts b/modules/angular2/test/change_detection/change_detector_config.ts index c813fc203d..feafbf166e 100644 --- a/modules/angular2/test/change_detection/change_detector_config.ts +++ b/modules/angular2/test/change_detection/change_detector_config.ts @@ -237,16 +237,20 @@ class _DirectiveUpdating { 'noCallbacks': new _DirectiveUpdating( [_DirectiveUpdating.updateA('1', _DirectiveUpdating.recordNoCallbacks)], [_DirectiveUpdating.recordNoCallbacks]), - 'readingDirectives': new _DirectiveUpdating([ - BindingRecord.createForHostProperty(new DirectiveIndex(0, 0), - _getParser().parseBinding('a', 'location'), PROP_NAME) - ], - [_DirectiveUpdating.basicRecords[0]]), - 'interpolation': new _DirectiveUpdating([ - BindingRecord.createForElement(_getParser().parseInterpolation('B{{a}}A', 'location'), 0, - PROP_NAME) - ], - []) + 'readingDirectives': + new _DirectiveUpdating( + [ + BindingRecord.createForHostProperty( + new DirectiveIndex(0, 0), _getParser().parseBinding('a', 'location'), PROP_NAME) + ], + [_DirectiveUpdating.basicRecords[0]]), + 'interpolation': + new _DirectiveUpdating( + [ + BindingRecord.createForElement(_getParser().parseInterpolation('B{{a}}A', 'location'), + 0, PROP_NAME) + ], + []) }; } diff --git a/modules/angular2/test/core/compiler/compiler_spec.ts b/modules/angular2/test/core/compiler/compiler_spec.ts index 467bcd9223..fafc5c2c0f 100644 --- a/modules/angular2/test/core/compiler/compiler_spec.ts +++ b/modules/angular2/test/core/compiler/compiler_spec.ts @@ -317,11 +317,12 @@ export function main() { var mainProtoView = createProtoView([createComponentElementBinder(directiveResolver, NestedComponent)]); var nestedProtoView = createProtoView(); - var compiler = createCompiler([ - createRenderProtoView([createRenderComponentElementBinder(0)]), - createRenderProtoView() - ], - [[rootProtoView], [mainProtoView], [nestedProtoView]]); + var compiler = createCompiler( + [ + createRenderProtoView([createRenderComponentElementBinder(0)]), + createRenderProtoView() + ], + [[rootProtoView], [mainProtoView], [nestedProtoView]]); compiler.compileInHost(MainComponent) .then((protoViewRef) => { expect(internalProtoView(protoViewRef).elementBinders[0].nestedProtoView) diff --git a/modules/benchmarks/e2e_test/naive_infinite_scroll_spec.ts b/modules/benchmarks/e2e_test/naive_infinite_scroll_spec.ts index 2f91e611a0..454915a60f 100644 --- a/modules/benchmarks/e2e_test/naive_infinite_scroll_spec.ts +++ b/modules/benchmarks/e2e_test/naive_infinite_scroll_spec.ts @@ -14,26 +14,22 @@ describe('ng2 naive infinite scroll benchmark', function() { var cells = `${ allScrollItems } .row *`; var stageButtons = `${ allScrollItems } .row stage-buttons button`; - var count = - function(selector) { - return browser.executeScript(`return ` + - `document.querySelectorAll("${ selector }").length;`); - } + var count = function(selector) { + return browser.executeScript(`return ` + + `document.querySelectorAll("${ selector }").length;`); + }; - var clickFirstOf = - function(selector) { - return browser.executeScript(`document.querySelector("${ selector }").click();`); - } + var clickFirstOf = function(selector) { + return browser.executeScript(`document.querySelector("${ selector }").click();`); + }; - var firstTextOf = - function(selector) { - return browser.executeScript(`return ` + - `document.querySelector("${ selector }").innerText;`); - } + var firstTextOf = function(selector) { + return browser.executeScript(`return ` + + `document.querySelector("${ selector }").innerText;`); + }; - // Make sure rows are rendered - count(allScrollItems) - .then(function(c) { expect(c).toEqual(expectedRowCount); }); + // Make sure rows are rendered + count(allScrollItems).then(function(c) { expect(c).toEqual(expectedRowCount); }); // Make sure cells are rendered count(cells).then(function(c) { expect(c).toEqual(expectedRowCount * expectedCellsPerRow); }); @@ -47,10 +43,9 @@ describe('ng2 naive infinite scroll benchmark', function() { firstTextOf(`${ stageButtons }:enabled`) .then(function(text) { expect(text).toEqual('Won'); }) }); - }) + }); - $("#reset-btn") - .click(); + $("#reset-btn").click(); $("#run-btn").click(); browser.wait(() => { return $('#done').getText().then(function() { return true; }, function() { return false; }); diff --git a/modules/benchmarks_external/src/compiler/compiler_benchmark.ts b/modules/benchmarks_external/src/compiler/compiler_benchmark.ts index a23400f320..c87eb154aa 100644 --- a/modules/benchmarks_external/src/compiler/compiler_benchmark.ts +++ b/modules/benchmarks_external/src/compiler/compiler_benchmark.ts @@ -24,61 +24,66 @@ function loadTemplate(templateId, repeatCount) { } angular.module('app', []) - .directive('dir0', [ - '$parse', - function($parse) { - return { - compile: function($element, $attrs) { - var expr = $parse($attrs.attr0); - return function($scope) { $scope.$watch(expr, angular.noop); } - } - }; - } - ]) - .directive('dir1', [ - '$parse', - function($parse) { - return { - compile: function($element, $attrs) { - var expr = $parse($attrs.attr1); - return function($scope) { $scope.$watch(expr, angular.noop); } - } - }; - } - ]) - .directive('dir2', [ - '$parse', - function($parse) { - return { - compile: function($element, $attrs) { - var expr = $parse($attrs.attr2); - return function($scope) { $scope.$watch(expr, angular.noop); } - } - }; - } - ]) - .directive('dir3', [ - '$parse', - function($parse) { - return { - compile: function($element, $attrs) { - var expr = $parse($attrs.attr3); - return function($scope) { $scope.$watch(expr, angular.noop); } - } - }; - } - ]) - .directive('dir4', [ - '$parse', - function($parse) { - return { - compile: function($element, $attrs) { - var expr = $parse($attrs.attr4); - return function($scope) { $scope.$watch(expr, angular.noop); } - } - }; - } - ]) + .directive('dir0', + [ + '$parse', + function($parse) { + return { + compile: function($element, $attrs) { + var expr = $parse($attrs.attr0); + return function($scope) { $scope.$watch(expr, angular.noop); } + } + }; + } + ]) + .directive('dir1', + [ + '$parse', + function($parse) { + return { + compile: function($element, $attrs) { + var expr = $parse($attrs.attr1); + return function($scope) { $scope.$watch(expr, angular.noop); } + } + }; + } + ]) + .directive('dir2', + [ + '$parse', + function($parse) { + return { + compile: function($element, $attrs) { + var expr = $parse($attrs.attr2); + return function($scope) { $scope.$watch(expr, angular.noop); } + } + }; + } + ]) + .directive('dir3', + [ + '$parse', + function($parse) { + return { + compile: function($element, $attrs) { + var expr = $parse($attrs.attr3); + return function($scope) { $scope.$watch(expr, angular.noop); } + } + }; + } + ]) + .directive('dir4', + [ + '$parse', + function($parse) { + return { + compile: function($element, $attrs) { + var expr = $parse($attrs.attr4); + return function($scope) { $scope.$watch(expr, angular.noop); } + } + }; + } + ]) .run([ '$compile', function($compile) { diff --git a/modules/benchmarks_external/src/tree/tree_benchmark.ts b/modules/benchmarks_external/src/tree/tree_benchmark.ts index 4a5b61feca..4ec5df35c6 100644 --- a/modules/benchmarks_external/src/tree/tree_benchmark.ts +++ b/modules/benchmarks_external/src/tree/tree_benchmark.ts @@ -19,41 +19,42 @@ angular.module('app', []) }) // special directive for "if" as angular 1.3 does not support // recursive components. - .directive('treeIf', [ - '$compile', - '$parse', - function($compile, $parse) { - var transcludeFn; - return { - compile: function(element, attrs) { - var expr = $parse(attrs.treeIf); - var template = ''; - var transclude; - return function($scope, $element, $attrs) { - if (!transclude) { - transclude = $compile(template); - } - var childScope; - var childElement; - $scope.$watch(expr, function(newValue) { - if (childScope) { - childScope.$destroy(); - childElement.remove(); - childScope = null; - childElement = null; - } - if (newValue) { - childScope = $scope.$new(); - childElement = - transclude(childScope, function(clone) { $element.append(clone); }); - } - }); - } + .directive('treeIf', + [ + '$compile', + '$parse', + function($compile, $parse) { + var transcludeFn; + return { + compile: function(element, attrs) { + var expr = $parse(attrs.treeIf); + var template = ''; + var transclude; + return function($scope, $element, $attrs) { + if (!transclude) { + transclude = $compile(template); + } + var childScope; + var childElement; + $scope.$watch(expr, function(newValue) { + if (childScope) { + childScope.$destroy(); + childElement.remove(); + childScope = null; + childElement = null; + } + if (newValue) { + childScope = $scope.$new(); + childElement = transclude(childScope, + function(clone) { $element.append(clone); }); + } + }); + } - } - } - } - ]) + } + } + } + ]) .config([ '$compileProvider', function($compileProvider) { $compileProvider.debugInfoEnabled(false); } diff --git a/modules/benchpress/src/sample_description.ts b/modules/benchpress/src/sample_description.ts index 13a4e1e871..dc0824877f 100644 --- a/modules/benchpress/src/sample_description.ts +++ b/modules/benchpress/src/sample_description.ts @@ -26,12 +26,13 @@ export class SampleDescription { var _BINDINGS = [ bind(SampleDescription) .toFactory((metric, id, forceGc, userAgent, validator, defaultDesc, userDesc) => - new SampleDescription(id, [ - {'forceGc': forceGc, 'userAgent': userAgent}, - validator.describe(), - defaultDesc, - userDesc - ], + new SampleDescription(id, + [ + {'forceGc': forceGc, 'userAgent': userAgent}, + validator.describe(), + defaultDesc, + userDesc + ], metric.describe()), [ Metric, diff --git a/modules/benchpress/test/metric/perflog_metric_spec.ts b/modules/benchpress/test/metric/perflog_metric_spec.ts index 814a539c54..2acc5be18e 100644 --- a/modules/benchpress/test/metric/perflog_metric_spec.ts +++ b/modules/benchpress/test/metric/perflog_metric_spec.ts @@ -333,14 +333,15 @@ export function main() { describe('frame metrics', () => { it('should calculate mean frame time', inject([AsyncTestCompleter], (async) => { - aggregate([ - eventFactory.markStart('frameCapture', 0), - eventFactory.instant('frame', 1), - eventFactory.instant('frame', 3), - eventFactory.instant('frame', 4), - eventFactory.markEnd('frameCapture', 5) - ], - null, true) + aggregate( + [ + eventFactory.markStart('frameCapture', 0), + eventFactory.instant('frame', 1), + eventFactory.instant('frame', 3), + eventFactory.instant('frame', 4), + eventFactory.markEnd('frameCapture', 5) + ], + null, true) .then((data) => { expect(data['frameTime.mean']).toBe(((3 - 1) + (4 - 3)) / 2); async.done(); @@ -372,11 +373,12 @@ export function main() { it('should throw if trying to capture twice', inject([AsyncTestCompleter], (async) => { PromiseWrapper.catchError( - aggregate([ - eventFactory.markStart('frameCapture', 3), - eventFactory.markStart('frameCapture', 4) - ], - null, true), + aggregate( + [ + eventFactory.markStart('frameCapture', 3), + eventFactory.markStart('frameCapture', 4) + ], + null, true), (err) => { expect(() => { throw err; }) .toThrowError('can capture frames only once per benchmark run'); @@ -405,17 +407,18 @@ export function main() { })); it('should calculate best and worst frame time', inject([AsyncTestCompleter], (async) => { - aggregate([ - eventFactory.markStart('frameCapture', 0), - eventFactory.instant('frame', 1), - eventFactory.instant('frame', 9), - eventFactory.instant('frame', 15), - eventFactory.instant('frame', 18), - eventFactory.instant('frame', 28), - eventFactory.instant('frame', 32), - eventFactory.markEnd('frameCapture', 10) - ], - null, true) + aggregate( + [ + eventFactory.markStart('frameCapture', 0), + eventFactory.instant('frame', 1), + eventFactory.instant('frame', 9), + eventFactory.instant('frame', 15), + eventFactory.instant('frame', 18), + eventFactory.instant('frame', 28), + eventFactory.instant('frame', 32), + eventFactory.markEnd('frameCapture', 10) + ], + null, true) .then((data) => { expect(data['frameTime.worst']).toBe(10); expect(data['frameTime.best']).toBe(3); @@ -425,14 +428,15 @@ export function main() { it('should calculate percentage of smoothness to be good', inject([AsyncTestCompleter], (async) => { - aggregate([ - eventFactory.markStart('frameCapture', 0), - eventFactory.instant('frame', 1), - eventFactory.instant('frame', 2), - eventFactory.instant('frame', 3), - eventFactory.markEnd('frameCapture', 4) - ], - null, true) + aggregate( + [ + eventFactory.markStart('frameCapture', 0), + eventFactory.instant('frame', 1), + eventFactory.instant('frame', 2), + eventFactory.instant('frame', 3), + eventFactory.markEnd('frameCapture', 4) + ], + null, true) .then((data) => { expect(data['frameTime.smooth']).toBe(1.0); async.done(); @@ -441,16 +445,17 @@ export function main() { it('should calculate percentage of smoothness to be bad', inject([AsyncTestCompleter], (async) => { - aggregate([ - eventFactory.markStart('frameCapture', 0), - eventFactory.instant('frame', 1), - eventFactory.instant('frame', 2), - eventFactory.instant('frame', 22), - eventFactory.instant('frame', 23), - eventFactory.instant('frame', 24), - eventFactory.markEnd('frameCapture', 4) - ], - null, true) + aggregate( + [ + eventFactory.markStart('frameCapture', 0), + eventFactory.instant('frame', 1), + eventFactory.instant('frame', 2), + eventFactory.instant('frame', 22), + eventFactory.instant('frame', 23), + eventFactory.instant('frame', 24), + eventFactory.markEnd('frameCapture', 4) + ], + null, true) .then((data) => { expect(data['frameTime.smooth']).toBe(0.75); async.done(); @@ -591,11 +596,12 @@ export function main() { describe('microMetrics', () => { it('should report micro metrics', inject([AsyncTestCompleter], (async) => { - aggregate([ - eventFactory.markStart('mm1', 0), - eventFactory.markEnd('mm1', 5), - ], - {'mm1': 'micro metric 1'}) + aggregate( + [ + eventFactory.markStart('mm1', 0), + eventFactory.markEnd('mm1', 5), + ], + {'mm1': 'micro metric 1'}) .then((data) => { expect(data['mm1']).toBe(5.0); async.done(); @@ -615,11 +621,12 @@ export function main() { })); it('should report micro metric averages', inject([AsyncTestCompleter], (async) => { - aggregate([ - eventFactory.markStart('mm1*20', 0), - eventFactory.markEnd('mm1*20', 5), - ], - {'mm1': 'micro metric 1'}) + aggregate( + [ + eventFactory.markStart('mm1*20', 0), + eventFactory.markEnd('mm1*20', 5), + ], + {'mm1': 'micro metric 1'}) .then((data) => { expect(data['mm1']).toBe(5 / 20); async.done(); diff --git a/modules/benchpress/test/webdriver/chrome_driver_extension_spec.ts b/modules/benchpress/test/webdriver/chrome_driver_extension_spec.ts index 6ad8419930..e9052abc68 100644 --- a/modules/benchpress/test/webdriver/chrome_driver_extension_spec.ts +++ b/modules/benchpress/test/webdriver/chrome_driver_extension_spec.ts @@ -277,10 +277,11 @@ export function main() { it('should throw an error on buffer overflow', inject([AsyncTestCompleter], (async) => { PromiseWrapper.catchError( - createExtension([ - chromeTimelineEvents.start('FunctionCall', 1234), - ], - 'Tracing.bufferUsage') + createExtension( + [ + chromeTimelineEvents.start('FunctionCall', 1234), + ], + 'Tracing.bufferUsage') .readPerfLog(), (err) => { expect(() => { throw err; }) diff --git a/modules/rtts_assert/src/rtts_assert.ts b/modules/rtts_assert/src/rtts_assert.ts index d23b5fa456..dbd98b82d7 100644 --- a/modules/rtts_assert/src/rtts_assert.ts +++ b/modules/rtts_assert/src/rtts_assert.ts @@ -204,23 +204,22 @@ function formatErrors(errors, indent = ' ') { // assert a type of given value and throw if does not pass var type: any = function(actual, T) { - var errors = []; - // currentStack = []; + var errors = []; + // currentStack = []; - if (!isType(actual, T, errors)) { - // console.log(JSON.stringify(errors, null, ' ')); - // TODO(vojta): print "an instance of" only if T starts with uppercase. - var msg = - 'Expected an instance of ' + prettyPrint(T) + ', got ' + prettyPrint(actual) + '!'; - if (errors.length) { - msg += '\n' + formatErrors(errors); - } - - throw new Error(msg); - } - return actual; + if (!isType(actual, T, errors)) { + // console.log(JSON.stringify(errors, null, ' ')); + // TODO(vojta): print "an instance of" only if T starts with uppercase. + var msg = 'Expected an instance of ' + prettyPrint(T) + ', got ' + prettyPrint(actual) + '!'; + if (errors.length) { + msg += '\n' + formatErrors(errors); } + throw new Error(msg); + } + return actual; +} + function returnType(actual, T) { var errors = []; // currentStack = []; @@ -303,46 +302,45 @@ function define(classOrName, check) { return cls; } -var assert: any = - function(value) { - return { - is: function is(...types) { - // var errors = [] - var allErrors = []; - var errors; - for (var i = 0; i < types.length; i++) { - var type = types[i]; - errors = []; +var assert: any = function(value) { + return { + is: function is(...types) { + // var errors = [] + var allErrors = []; + var errors; + for (var i = 0; i < types.length; i++) { + var type = types[i]; + errors = []; - if (isType(value, type, errors)) { - return true; - } - - // if no errors, merge multiple "is not instance of " into x/y/z ? - allErrors.push(prettyPrint(value) + ' is not instance of ' + prettyPrint(type)); - if (errors.length) { - allErrors.push(errors); - } - } - - // if (types.length > 1) { - // currentStack.push(['has to be ' + types.map(prettyPrint).join(' or '), - // ...allErrors]); - // } else { - currentStack.push(...allErrors); - // } - return false; + if (isType(value, type, errors)) { + return true; } - }; + + // if no errors, merge multiple "is not instance of " into x/y/z ? + allErrors.push(prettyPrint(value) + ' is not instance of ' + prettyPrint(type)); + if (errors.length) { + allErrors.push(errors); + } + } + + // if (types.length > 1) { + // currentStack.push(['has to be ' + types.map(prettyPrint).join(' or '), + // ...allErrors]); + // } else { + currentStack.push(...allErrors); + // } + return false; } + }; +}; - // PUBLIC API +// PUBLIC API - // asserting API +// asserting API - // throw if no type provided - assert.type = type; +// throw if no type provided +assert.type = type; for (var prop in primitives) { assert.type[prop] = primitives[prop]; } diff --git a/tools/broccoli/tree-differ.ts b/tools/broccoli/tree-differ.ts index 15c35ab7b3..7439d03e5b 100644 --- a/tools/broccoli/tree-differ.ts +++ b/tools/broccoli/tree-differ.ts @@ -166,4 +166,8 @@ function pad(value, length) { } -enum FileStatus { ADDED, UNCHANGED, CHANGED } +enum FileStatus { + ADDED, + UNCHANGED, + CHANGED +}