chore: update files to match clang-format 1.0.21.

This commit is contained in:
Martin Probst 2015-06-19 10:18:44 -07:00
parent 254e58c28f
commit 920982c4e8
14 changed files with 383 additions and 337 deletions

View File

@ -17,7 +17,8 @@ enum TokenType {
NUMBER NUMBER
} }
@Injectable() export class Lexer { @Injectable()
export class Lexer {
tokenize(text: string): List<any> { tokenize(text: string): List<any> {
var scanner = new _Scanner(text); var scanner = new _Scanner(text);
var tokens = []; var tokens = [];

View File

@ -28,12 +28,11 @@ export function assertionsEnabled(): boolean {
// TODO: remove calls to assert in production environment // TODO: remove calls to assert in production environment
// Note: Can't just export this and import in in other files // Note: Can't just export this and import in in other files
// as `assert` is a reserved keyword in Dart // as `assert` is a reserved keyword in Dart
_global.assert = _global.assert = function assert(condition) {
function assert(condition) { if (assertionsEnabled_) {
if (assertionsEnabled_) { _global['assert'].call(condition);
_global['assert'].call(condition); }
} };
}
// This function is needed only to properly support Dart's const expressions // This function is needed only to properly support Dart's const expressions
// see https://github.com/angular/ts2dart/pull/151 for more info // see https://github.com/angular/ts2dart/pull/151 for more info
export function CONST_EXPR<T>(expr: T): T { export function CONST_EXPR<T>(expr: T): T {

View File

@ -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,
export enum ResponseTypes {Basic, Cors, Default, Error, Opaque} Cors,
Default,
Error,
Opaque
}

View File

@ -172,103 +172,97 @@ export function iit(name, fn) {
// gives us bad error messages in tests. // gives us bad error messages in tests.
// The only way to do this in Jasmine is to monkey patch a method // The only way to do this in Jasmine is to monkey patch a method
// to the object :-( // to the object :-(
Map.prototype['jasmineToString'] = Map.prototype['jasmineToString'] = function() {
function() { var m = this;
var m = this; if (!m) {
if (!m) { return '' + m;
return '' + m; }
} var res = [];
var res = []; m.forEach((v, k) => { res.push(`${k}:${v}`); });
m.forEach((v, k) => { res.push(`${k}:${v}`); }); return `{ ${res.join(',')} }`;
return `{ ${res.join(',')} }`; };
}
_global.beforeEach(function() { _global.beforeEach(function() {
jasmine.addMatchers({ jasmine.addMatchers({
// Custom handler for Map as Jasmine does not support it yet // Custom handler for Map as Jasmine does not support it yet
toEqual: function(util, customEqualityTesters) { toEqual: function(util, customEqualityTesters) {
return { return {
compare: function(actual, expected) { compare: function(actual, expected) {
return {pass: util.equals(actual, expected, [compareMap])}; return {pass: util.equals(actual, expected, [compareMap])};
} }
}; };
function compareMap(actual, expected) { function compareMap(actual, expected) {
if (actual instanceof Map) { if (actual instanceof Map) {
var pass = actual.size === expected.size; var pass = actual.size === expected.size;
if (pass) { if (pass) {
actual.forEach((v, k) => { pass = pass && util.equals(v, expected.get(k)); }); actual.forEach((v, k) => { pass = pass && util.equals(v, expected.get(k)); });
}
return pass;
} else {
return undefined;
}
} }
}, 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 { return {
compare: function(actual, expectedClass) { pass: pass,
var pass = typeof actual === 'object' && typeof actual.then === 'function'; get message() {
return { return 'Expected ' + actual + ' to be an instance of ' + expectedClass;
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(", ");
}
};
} }
}; };
} }
}); };
}); },
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 { export interface GuinessCompatibleSpy extends jasmine.Spy {
/** By chaining the spy with and.returnValue, all calls to the function will return a specific /** By chaining the spy with and.returnValue, all calls to the function will return a specific

View File

@ -237,16 +237,20 @@ class _DirectiveUpdating {
'noCallbacks': new _DirectiveUpdating( 'noCallbacks': new _DirectiveUpdating(
[_DirectiveUpdating.updateA('1', _DirectiveUpdating.recordNoCallbacks)], [_DirectiveUpdating.updateA('1', _DirectiveUpdating.recordNoCallbacks)],
[_DirectiveUpdating.recordNoCallbacks]), [_DirectiveUpdating.recordNoCallbacks]),
'readingDirectives': new _DirectiveUpdating([ 'readingDirectives':
BindingRecord.createForHostProperty(new DirectiveIndex(0, 0), new _DirectiveUpdating(
_getParser().parseBinding('a', 'location'), PROP_NAME) [
], BindingRecord.createForHostProperty(
[_DirectiveUpdating.basicRecords[0]]), new DirectiveIndex(0, 0), _getParser().parseBinding('a', 'location'), PROP_NAME)
'interpolation': new _DirectiveUpdating([ ],
BindingRecord.createForElement(_getParser().parseInterpolation('B{{a}}A', 'location'), 0, [_DirectiveUpdating.basicRecords[0]]),
PROP_NAME) 'interpolation':
], new _DirectiveUpdating(
[]) [
BindingRecord.createForElement(_getParser().parseInterpolation('B{{a}}A', 'location'),
0, PROP_NAME)
],
[])
}; };
} }

View File

@ -317,11 +317,12 @@ export function main() {
var mainProtoView = var mainProtoView =
createProtoView([createComponentElementBinder(directiveResolver, NestedComponent)]); createProtoView([createComponentElementBinder(directiveResolver, NestedComponent)]);
var nestedProtoView = createProtoView(); var nestedProtoView = createProtoView();
var compiler = createCompiler([ var compiler = createCompiler(
createRenderProtoView([createRenderComponentElementBinder(0)]), [
createRenderProtoView() createRenderProtoView([createRenderComponentElementBinder(0)]),
], createRenderProtoView()
[[rootProtoView], [mainProtoView], [nestedProtoView]]); ],
[[rootProtoView], [mainProtoView], [nestedProtoView]]);
compiler.compileInHost(MainComponent) compiler.compileInHost(MainComponent)
.then((protoViewRef) => { .then((protoViewRef) => {
expect(internalProtoView(protoViewRef).elementBinders[0].nestedProtoView) expect(internalProtoView(protoViewRef).elementBinders[0].nestedProtoView)

View File

@ -14,26 +14,22 @@ describe('ng2 naive infinite scroll benchmark', function() {
var cells = `${ allScrollItems } .row *`; var cells = `${ allScrollItems } .row *`;
var stageButtons = `${ allScrollItems } .row stage-buttons button`; var stageButtons = `${ allScrollItems } .row stage-buttons button`;
var count = var count = function(selector) {
function(selector) { return browser.executeScript(`return ` +
return browser.executeScript(`return ` + `document.querySelectorAll("${ selector }").length;`);
`document.querySelectorAll("${ selector }").length;`); };
}
var clickFirstOf = var clickFirstOf = function(selector) {
function(selector) { return browser.executeScript(`document.querySelector("${ selector }").click();`);
return browser.executeScript(`document.querySelector("${ selector }").click();`); };
}
var firstTextOf = var firstTextOf = function(selector) {
function(selector) { return browser.executeScript(`return ` +
return browser.executeScript(`return ` + `document.querySelector("${ selector }").innerText;`);
`document.querySelector("${ selector }").innerText;`); };
}
// Make sure rows are rendered // Make sure rows are rendered
count(allScrollItems) count(allScrollItems).then(function(c) { expect(c).toEqual(expectedRowCount); });
.then(function(c) { expect(c).toEqual(expectedRowCount); });
// Make sure cells are rendered // Make sure cells are rendered
count(cells).then(function(c) { expect(c).toEqual(expectedRowCount * expectedCellsPerRow); }); count(cells).then(function(c) { expect(c).toEqual(expectedRowCount * expectedCellsPerRow); });
@ -47,10 +43,9 @@ describe('ng2 naive infinite scroll benchmark', function() {
firstTextOf(`${ stageButtons }:enabled`) firstTextOf(`${ stageButtons }:enabled`)
.then(function(text) { expect(text).toEqual('Won'); }) .then(function(text) { expect(text).toEqual('Won'); })
}); });
}) });
$("#reset-btn") $("#reset-btn").click();
.click();
$("#run-btn").click(); $("#run-btn").click();
browser.wait(() => { browser.wait(() => {
return $('#done').getText().then(function() { return true; }, function() { return false; }); return $('#done').getText().then(function() { return true; }, function() { return false; });

View File

@ -24,61 +24,66 @@ function loadTemplate(templateId, repeatCount) {
} }
angular.module('app', []) angular.module('app', [])
.directive('dir0', [ .directive('dir0',
'$parse', [
function($parse) { '$parse',
return { function($parse) {
compile: function($element, $attrs) { return {
var expr = $parse($attrs.attr0); compile: function($element, $attrs) {
return function($scope) { $scope.$watch(expr, angular.noop); } var expr = $parse($attrs.attr0);
} return function($scope) { $scope.$watch(expr, angular.noop); }
}; }
} };
]) }
.directive('dir1', [ ])
'$parse', .directive('dir1',
function($parse) { [
return { '$parse',
compile: function($element, $attrs) { function($parse) {
var expr = $parse($attrs.attr1); return {
return function($scope) { $scope.$watch(expr, angular.noop); } compile: function($element, $attrs) {
} var expr = $parse($attrs.attr1);
}; return function($scope) { $scope.$watch(expr, angular.noop); }
} }
]) };
.directive('dir2', [ }
'$parse', ])
function($parse) { .directive('dir2',
return { [
compile: function($element, $attrs) { '$parse',
var expr = $parse($attrs.attr2); function($parse) {
return function($scope) { $scope.$watch(expr, angular.noop); } return {
} compile: function($element, $attrs) {
}; var expr = $parse($attrs.attr2);
} return function($scope) { $scope.$watch(expr, angular.noop); }
]) }
.directive('dir3', [ };
'$parse', }
function($parse) { ])
return { .directive('dir3',
compile: function($element, $attrs) { [
var expr = $parse($attrs.attr3); '$parse',
return function($scope) { $scope.$watch(expr, angular.noop); } 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) { .directive('dir4',
var expr = $parse($attrs.attr4); [
return function($scope) { $scope.$watch(expr, angular.noop); } '$parse',
} function($parse) {
}; return {
} compile: function($element, $attrs) {
]) var expr = $parse($attrs.attr4);
return function($scope) { $scope.$watch(expr, angular.noop); }
}
};
}
])
.run([ .run([
'$compile', '$compile',
function($compile) { function($compile) {

View File

@ -19,41 +19,42 @@ angular.module('app', [])
}) })
// special directive for "if" as angular 1.3 does not support // special directive for "if" as angular 1.3 does not support
// recursive components. // recursive components.
.directive('treeIf', [ .directive('treeIf',
'$compile', [
'$parse', '$compile',
function($compile, $parse) { '$parse',
var transcludeFn; function($compile, $parse) {
return { var transcludeFn;
compile: function(element, attrs) { return {
var expr = $parse(attrs.treeIf); compile: function(element, attrs) {
var template = '<tree data="' + attrs.treeIf + '"></tree>'; var expr = $parse(attrs.treeIf);
var transclude; var template = '<tree data="' + attrs.treeIf + '"></tree>';
return function($scope, $element, $attrs) { var transclude;
if (!transclude) { return function($scope, $element, $attrs) {
transclude = $compile(template); if (!transclude) {
} transclude = $compile(template);
var childScope; }
var childElement; var childScope;
$scope.$watch(expr, function(newValue) { var childElement;
if (childScope) { $scope.$watch(expr, function(newValue) {
childScope.$destroy(); if (childScope) {
childElement.remove(); childScope.$destroy();
childScope = null; childElement.remove();
childElement = null; childScope = null;
} childElement = null;
if (newValue) { }
childScope = $scope.$new(); if (newValue) {
childElement = childScope = $scope.$new();
transclude(childScope, function(clone) { $element.append(clone); }); childElement = transclude(childScope,
} function(clone) { $element.append(clone); });
}); }
} });
}
} }
} }
} }
]) ])
.config([ .config([
'$compileProvider', '$compileProvider',
function($compileProvider) { $compileProvider.debugInfoEnabled(false); } function($compileProvider) { $compileProvider.debugInfoEnabled(false); }

View File

@ -26,12 +26,13 @@ export class SampleDescription {
var _BINDINGS = [ var _BINDINGS = [
bind(SampleDescription) bind(SampleDescription)
.toFactory((metric, id, forceGc, userAgent, validator, defaultDesc, userDesc) => .toFactory((metric, id, forceGc, userAgent, validator, defaultDesc, userDesc) =>
new SampleDescription(id, [ new SampleDescription(id,
{'forceGc': forceGc, 'userAgent': userAgent}, [
validator.describe(), {'forceGc': forceGc, 'userAgent': userAgent},
defaultDesc, validator.describe(),
userDesc defaultDesc,
], userDesc
],
metric.describe()), metric.describe()),
[ [
Metric, Metric,

View File

@ -333,14 +333,15 @@ export function main() {
describe('frame metrics', () => { describe('frame metrics', () => {
it('should calculate mean frame time', inject([AsyncTestCompleter], (async) => { it('should calculate mean frame time', inject([AsyncTestCompleter], (async) => {
aggregate([ aggregate(
eventFactory.markStart('frameCapture', 0), [
eventFactory.instant('frame', 1), eventFactory.markStart('frameCapture', 0),
eventFactory.instant('frame', 3), eventFactory.instant('frame', 1),
eventFactory.instant('frame', 4), eventFactory.instant('frame', 3),
eventFactory.markEnd('frameCapture', 5) eventFactory.instant('frame', 4),
], eventFactory.markEnd('frameCapture', 5)
null, true) ],
null, true)
.then((data) => { .then((data) => {
expect(data['frameTime.mean']).toBe(((3 - 1) + (4 - 3)) / 2); expect(data['frameTime.mean']).toBe(((3 - 1) + (4 - 3)) / 2);
async.done(); async.done();
@ -372,11 +373,12 @@ export function main() {
it('should throw if trying to capture twice', inject([AsyncTestCompleter], (async) => { it('should throw if trying to capture twice', inject([AsyncTestCompleter], (async) => {
PromiseWrapper.catchError( PromiseWrapper.catchError(
aggregate([ aggregate(
eventFactory.markStart('frameCapture', 3), [
eventFactory.markStart('frameCapture', 4) eventFactory.markStart('frameCapture', 3),
], eventFactory.markStart('frameCapture', 4)
null, true), ],
null, true),
(err) => { (err) => {
expect(() => { throw err; }) expect(() => { throw err; })
.toThrowError('can capture frames only once per benchmark run'); .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) => { it('should calculate best and worst frame time', inject([AsyncTestCompleter], (async) => {
aggregate([ aggregate(
eventFactory.markStart('frameCapture', 0), [
eventFactory.instant('frame', 1), eventFactory.markStart('frameCapture', 0),
eventFactory.instant('frame', 9), eventFactory.instant('frame', 1),
eventFactory.instant('frame', 15), eventFactory.instant('frame', 9),
eventFactory.instant('frame', 18), eventFactory.instant('frame', 15),
eventFactory.instant('frame', 28), eventFactory.instant('frame', 18),
eventFactory.instant('frame', 32), eventFactory.instant('frame', 28),
eventFactory.markEnd('frameCapture', 10) eventFactory.instant('frame', 32),
], eventFactory.markEnd('frameCapture', 10)
null, true) ],
null, true)
.then((data) => { .then((data) => {
expect(data['frameTime.worst']).toBe(10); expect(data['frameTime.worst']).toBe(10);
expect(data['frameTime.best']).toBe(3); expect(data['frameTime.best']).toBe(3);
@ -425,14 +428,15 @@ export function main() {
it('should calculate percentage of smoothness to be good', it('should calculate percentage of smoothness to be good',
inject([AsyncTestCompleter], (async) => { inject([AsyncTestCompleter], (async) => {
aggregate([ aggregate(
eventFactory.markStart('frameCapture', 0), [
eventFactory.instant('frame', 1), eventFactory.markStart('frameCapture', 0),
eventFactory.instant('frame', 2), eventFactory.instant('frame', 1),
eventFactory.instant('frame', 3), eventFactory.instant('frame', 2),
eventFactory.markEnd('frameCapture', 4) eventFactory.instant('frame', 3),
], eventFactory.markEnd('frameCapture', 4)
null, true) ],
null, true)
.then((data) => { .then((data) => {
expect(data['frameTime.smooth']).toBe(1.0); expect(data['frameTime.smooth']).toBe(1.0);
async.done(); async.done();
@ -441,16 +445,17 @@ export function main() {
it('should calculate percentage of smoothness to be bad', it('should calculate percentage of smoothness to be bad',
inject([AsyncTestCompleter], (async) => { inject([AsyncTestCompleter], (async) => {
aggregate([ aggregate(
eventFactory.markStart('frameCapture', 0), [
eventFactory.instant('frame', 1), eventFactory.markStart('frameCapture', 0),
eventFactory.instant('frame', 2), eventFactory.instant('frame', 1),
eventFactory.instant('frame', 22), eventFactory.instant('frame', 2),
eventFactory.instant('frame', 23), eventFactory.instant('frame', 22),
eventFactory.instant('frame', 24), eventFactory.instant('frame', 23),
eventFactory.markEnd('frameCapture', 4) eventFactory.instant('frame', 24),
], eventFactory.markEnd('frameCapture', 4)
null, true) ],
null, true)
.then((data) => { .then((data) => {
expect(data['frameTime.smooth']).toBe(0.75); expect(data['frameTime.smooth']).toBe(0.75);
async.done(); async.done();
@ -591,11 +596,12 @@ export function main() {
describe('microMetrics', () => { describe('microMetrics', () => {
it('should report micro metrics', inject([AsyncTestCompleter], (async) => { it('should report micro metrics', inject([AsyncTestCompleter], (async) => {
aggregate([ aggregate(
eventFactory.markStart('mm1', 0), [
eventFactory.markEnd('mm1', 5), eventFactory.markStart('mm1', 0),
], eventFactory.markEnd('mm1', 5),
{'mm1': 'micro metric 1'}) ],
{'mm1': 'micro metric 1'})
.then((data) => { .then((data) => {
expect(data['mm1']).toBe(5.0); expect(data['mm1']).toBe(5.0);
async.done(); async.done();
@ -615,11 +621,12 @@ export function main() {
})); }));
it('should report micro metric averages', inject([AsyncTestCompleter], (async) => { it('should report micro metric averages', inject([AsyncTestCompleter], (async) => {
aggregate([ aggregate(
eventFactory.markStart('mm1*20', 0), [
eventFactory.markEnd('mm1*20', 5), eventFactory.markStart('mm1*20', 0),
], eventFactory.markEnd('mm1*20', 5),
{'mm1': 'micro metric 1'}) ],
{'mm1': 'micro metric 1'})
.then((data) => { .then((data) => {
expect(data['mm1']).toBe(5 / 20); expect(data['mm1']).toBe(5 / 20);
async.done(); async.done();

View File

@ -277,10 +277,11 @@ export function main() {
it('should throw an error on buffer overflow', inject([AsyncTestCompleter], (async) => { it('should throw an error on buffer overflow', inject([AsyncTestCompleter], (async) => {
PromiseWrapper.catchError( PromiseWrapper.catchError(
createExtension([ createExtension(
chromeTimelineEvents.start('FunctionCall', 1234), [
], chromeTimelineEvents.start('FunctionCall', 1234),
'Tracing.bufferUsage') ],
'Tracing.bufferUsage')
.readPerfLog(), .readPerfLog(),
(err) => { (err) => {
expect(() => { throw err; }) expect(() => { throw err; })

View File

@ -204,23 +204,22 @@ function formatErrors(errors, indent = ' ') {
// assert a type of given value and throw if does not pass // assert a type of given value and throw if does not pass
var type: any = var type: any =
function(actual, T) { function(actual, T) {
var errors = []; var errors = [];
// currentStack = []; // currentStack = [];
if (!isType(actual, T, errors)) { if (!isType(actual, T, errors)) {
// console.log(JSON.stringify(errors, null, ' ')); // console.log(JSON.stringify(errors, null, ' '));
// TODO(vojta): print "an instance of" only if T starts with uppercase. // TODO(vojta): print "an instance of" only if T starts with uppercase.
var msg = var msg = 'Expected an instance of ' + prettyPrint(T) + ', got ' + prettyPrint(actual) + '!';
'Expected an instance of ' + prettyPrint(T) + ', got ' + prettyPrint(actual) + '!'; if (errors.length) {
if (errors.length) { msg += '\n' + formatErrors(errors);
msg += '\n' + formatErrors(errors);
}
throw new Error(msg);
}
return actual;
} }
throw new Error(msg);
}
return actual;
}
function returnType(actual, T) { function returnType(actual, T) {
var errors = []; var errors = [];
// currentStack = []; // currentStack = [];
@ -303,46 +302,45 @@ function define(classOrName, check) {
return cls; return cls;
} }
var assert: any = var assert: any = function(value) {
function(value) { return {
return { is: function is(...types) {
is: function is(...types) { // var errors = []
// var errors = [] var allErrors = [];
var allErrors = []; var errors;
var errors; for (var i = 0; i < types.length; i++) {
for (var i = 0; i < types.length; i++) { var type = types[i];
var type = types[i]; errors = [];
errors = [];
if (isType(value, type, errors)) { if (isType(value, type, errors)) {
return true; 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 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 // throw if no type provided
assert.type = type; assert.type = type;
for (var prop in primitives) { for (var prop in primitives) {
assert.type[prop] = primitives[prop]; assert.type[prop] = primitives[prop];
} }

View File

@ -166,4 +166,8 @@ function pad(value, length) {
} }
enum FileStatus { ADDED, UNCHANGED, CHANGED } enum FileStatus {
ADDED,
UNCHANGED,
CHANGED
}