mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
test(assert): adds new debugging assert() util
improves removing of console.debug statements fixes #8483
This commit is contained in:
committed by
Adam Bradley
parent
925be1533b
commit
ff1f340285
@@ -110,6 +110,7 @@
|
||||
"sassdoc": "2.1.20",
|
||||
"semver": "5.3.0",
|
||||
"serve-static": "1.11.1",
|
||||
"strip-function": "0.0.3",
|
||||
"systemjs": "0.19.38",
|
||||
"through2": "2.0.1",
|
||||
"ts-node": "1.3.0",
|
||||
|
||||
3
scripts/gulp/declarations.d.ts
vendored
3
scripts/gulp/declarations.d.ts
vendored
@@ -16,4 +16,5 @@ declare module 'rollup-plugin-node-resolve';
|
||||
declare module 'rollup-plugin-uglify';
|
||||
declare module 'semver';
|
||||
declare module 'vinyl';
|
||||
declare module 'yargs';
|
||||
declare module 'yargs';
|
||||
declare module 'strip-function';
|
||||
@@ -3,8 +3,8 @@ import { DIST_BUILD_ROOT, DIST_BUILD_ES2015_ROOT, DIST_BUILD_UMD_ROOT, ES5, ES_2
|
||||
import { copySourceToDest, copySwiperToPath, createTempTsConfig, deleteFiles, runNgc} from '../util';
|
||||
|
||||
|
||||
export function buildIonicAngularUmd(excludeSpec: boolean, done: Function) {
|
||||
const stream = copySourceToDest(DIST_BUILD_UMD_ROOT, excludeSpec, true);
|
||||
export function buildIonicAngularUmd(excludeSpec: boolean, stripDebug: boolean, done: Function) {
|
||||
const stream = copySourceToDest(DIST_BUILD_UMD_ROOT, excludeSpec, true, stripDebug);
|
||||
stream.on('end', () => {
|
||||
// the source files are copied, copy over a tsconfig from
|
||||
createTempTsConfig(['./**/*.ts'], ES5, UMD_MODULE, `${DIST_BUILD_UMD_ROOT}/tsconfig.json`);
|
||||
@@ -24,8 +24,8 @@ export function buildIonicAngularUmd(excludeSpec: boolean, done: Function) {
|
||||
});
|
||||
}
|
||||
|
||||
export function buildIonicAngularEsm(done: Function) {
|
||||
const stream = copySourceToDest(DIST_BUILD_ROOT, true, true);
|
||||
export function buildIonicAngularEsm(stripDebug: boolean, done: Function) {
|
||||
const stream = copySourceToDest(DIST_BUILD_ROOT, true, true, stripDebug);
|
||||
stream.on('end', () => {
|
||||
// the source files are copied, copy over a tsconfig from
|
||||
createTempTsConfig(['./**/*.ts'], ES5, ES_2015, `${DIST_BUILD_ROOT}/tsconfig.json`);
|
||||
@@ -44,8 +44,8 @@ export function buildIonicAngularEsm(done: Function) {
|
||||
});
|
||||
}
|
||||
|
||||
export function buildIonicPureEs6(done: Function) {
|
||||
const stream = copySourceToDest(DIST_BUILD_ES2015_ROOT, true, true);
|
||||
export function buildIonicPureEs6(stripDebug: boolean, done: Function) {
|
||||
const stream = copySourceToDest(DIST_BUILD_ES2015_ROOT, true, true, stripDebug);
|
||||
stream.on('end', () => {
|
||||
// the source files are copied, copy over a tsconfig from
|
||||
createTempTsConfig(['./**/*.ts'], ES_2015, ES_2015, `${DIST_BUILD_ES2015_ROOT}/tsconfig.json`);
|
||||
@@ -66,14 +66,14 @@ export function buildIonicPureEs6(done: Function) {
|
||||
|
||||
/* this task builds out the necessary stuff for karma */
|
||||
task('compile.karma', (done: Function) => {
|
||||
buildIonicAngularUmd(false, done);
|
||||
buildIonicAngularUmd(false, false, done);
|
||||
});
|
||||
|
||||
/* this task builds out the ionic-angular (commonjs and esm) directories for release */
|
||||
task('compile.release', (done: Function) => {
|
||||
buildIonicAngularEsm(() => {
|
||||
buildIonicAngularUmd(true, () => {
|
||||
buildIonicPureEs6(done);
|
||||
buildIonicAngularEsm(true, () => {
|
||||
buildIonicAngularUmd(true, true, () => {
|
||||
buildIonicPureEs6(true, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -20,7 +20,6 @@ task('nightly', (done: (err: any) => void) => {
|
||||
runSequence('release.pullLatest',
|
||||
'validate',
|
||||
'release.prepareReleasePackage',
|
||||
'release.removeDebugStatements',
|
||||
'release.publishNightly',
|
||||
done);
|
||||
});
|
||||
@@ -30,32 +29,19 @@ task('release', (done: (err: any) => void) => {
|
||||
'validate',
|
||||
'release.prepareReleasePackage',
|
||||
'release.copyProdVersion',
|
||||
'release.removeDebugStatements',
|
||||
'release.prepareChangelog',
|
||||
'release.publishNpmRelease',
|
||||
'release.publishGithubRelease',
|
||||
done);
|
||||
});
|
||||
|
||||
task('release.removeDebugStatements', (done: Function) => {
|
||||
glob(`${DIST_BUILD_ROOT}/**/*.js`, (err, filePaths) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
} else {
|
||||
// can make async if it's slow but it's fine for now
|
||||
for (let filePath of filePaths) {
|
||||
const fileContent = readFileSync(filePath).toString();
|
||||
const consoleFree = replaceAll(fileContent, 'console.debug', '// console.debug');
|
||||
const cleanedJs = replaceAll(consoleFree, 'debugger;', '// debugger;');
|
||||
writeFileSync(filePath, cleanedJs);
|
||||
}
|
||||
}
|
||||
}, done());
|
||||
task('release.test', (done: (err: any) => void) => {
|
||||
runSequence('validate',
|
||||
'release.prepareReleasePackage',
|
||||
'release.copyProdVersion',
|
||||
done);
|
||||
});
|
||||
|
||||
function replaceAll(input: string, tokenToReplace: string, replaceWith: string) {
|
||||
return input.split(tokenToReplace).join(replaceWith);
|
||||
}
|
||||
|
||||
task('release.publishGithubRelease', (done: Function) => {
|
||||
|
||||
@@ -190,7 +176,7 @@ task('release.sass', () => {
|
||||
});
|
||||
|
||||
task('release.pullLatest', (done: Function) => {
|
||||
exec('git status --porcelain', (err: Error, stdOut: string) =>{
|
||||
exec('git status --porcelain', (err: Error, stdOut: string) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
} else if ( stdOut && stdOut.length > 0) {
|
||||
|
||||
@@ -3,10 +3,12 @@ import { src, dest } from 'gulp';
|
||||
import { join } from 'path';
|
||||
import * as fs from 'fs';
|
||||
import { rollup } from 'rollup';
|
||||
import { Replacer } from 'strip-function';
|
||||
import * as commonjs from 'rollup-plugin-commonjs';
|
||||
import * as multiEntry from 'rollup-plugin-multi-entry';
|
||||
import * as nodeResolve from 'rollup-plugin-node-resolve';
|
||||
import * as uglify from 'rollup-plugin-uglify';
|
||||
import * as through from 'through2';
|
||||
|
||||
export function mergeObjects(obj1: any, obj2: any ) {
|
||||
if (! obj1) {
|
||||
@@ -50,7 +52,17 @@ export function createTempTsConfig(includeGlob: string[], target: string, module
|
||||
fs.writeFileSync(pathToWriteFile, json);
|
||||
}
|
||||
|
||||
export function copySourceToDest(destinationPath: string, excludeSpecs: boolean = true, excludeE2e: boolean = true) {
|
||||
function removeDebugStatements() {
|
||||
let replacer = new Replacer(['console.debug', 'assert']);
|
||||
return through.obj(function (file, encoding, callback) {
|
||||
const content = file.contents.toString();
|
||||
const cleanedJs = replacer.replace(content);
|
||||
file.contents = new Buffer(cleanedJs, 'utf8');
|
||||
callback(null, file);
|
||||
});
|
||||
};
|
||||
|
||||
export function copySourceToDest(destinationPath: string, excludeSpecs: boolean, excludeE2e: boolean, stripDebug: boolean) {
|
||||
let glob = [`${SRC_ROOT}/**/*.ts`];
|
||||
if (excludeSpecs) {
|
||||
glob.push(`!${SRC_ROOT}/**/*.spec.ts`);
|
||||
@@ -60,8 +72,11 @@ export function copySourceToDest(destinationPath: string, excludeSpecs: boolean
|
||||
if (excludeE2e) {
|
||||
glob.push(`!${SRC_ROOT}/components/*/test/*/*.ts`);
|
||||
}
|
||||
return src(glob)
|
||||
.pipe(dest(destinationPath));
|
||||
let stream = src(glob);
|
||||
if (stripDebug) {
|
||||
stream = stream.pipe(removeDebugStatements());
|
||||
}
|
||||
return stream.pipe(dest(destinationPath));
|
||||
}
|
||||
|
||||
export function copyGlobToDest(sourceGlob: string[], destPath: string) {
|
||||
|
||||
@@ -290,8 +290,6 @@ export class Animation {
|
||||
play(opts?: PlayOptions) {
|
||||
const dur = this.getDuration(opts);
|
||||
|
||||
// console.debug('Animation, play, duration', dur, 'easing', this._es);
|
||||
|
||||
// this is the top level animation and is in full control
|
||||
// of when the async play() should actually kick off
|
||||
// if there is no duration then it'll set the TO property immediately
|
||||
@@ -450,8 +448,6 @@ export class Animation {
|
||||
|
||||
function onTransitionEnd(ev: any) {
|
||||
// congrats! a successful transition completed!
|
||||
// console.debug('Animation onTransitionEnd', ev.target.nodeName, ev.propertyName);
|
||||
|
||||
// ensure transition end events and timeouts have been cleared
|
||||
self._clearAsync();
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import { nativeRaf, nativeTimeout, transitionEnd} from '../../util/dom';
|
||||
import { ScrollView } from '../../util/scroll-view';
|
||||
import { Tabs } from '../tabs/tabs';
|
||||
import { ViewController } from '../../navigation/view-controller';
|
||||
import { isTrueProperty } from '../../util/util';
|
||||
import { isTrueProperty, assert } from '../../util/util';
|
||||
|
||||
|
||||
/**
|
||||
@@ -182,8 +182,11 @@ export class Content extends Ion {
|
||||
* @private
|
||||
*/
|
||||
ngOnInit() {
|
||||
this._fixedEle = this._elementRef.nativeElement.children[0];
|
||||
this._scrollEle = this._elementRef.nativeElement.children[1];
|
||||
let children = this._elementRef.nativeElement.children;
|
||||
assert(children && children.length >= 2, 'content needs at least two children');
|
||||
|
||||
this._fixedEle = children[0];
|
||||
this._scrollEle = children[1];
|
||||
|
||||
this._zone.runOutsideAngular(() => {
|
||||
this._scroll = new ScrollView(this._scrollEle);
|
||||
@@ -250,7 +253,8 @@ export class Content extends Ion {
|
||||
}
|
||||
|
||||
_addListener(type: string, handler: any): Function {
|
||||
if (!this._scrollEle) { return; }
|
||||
assert(handler, 'handler must be valid');
|
||||
assert(this._scrollEle, '_scrollEle must be valid');
|
||||
|
||||
// ensure we're not creating duplicates
|
||||
this._scrollEle.removeEventListener(type, handler);
|
||||
@@ -489,16 +493,18 @@ export class Content extends Ion {
|
||||
|
||||
let ele: HTMLElement = this._elementRef.nativeElement;
|
||||
if (!ele) {
|
||||
assert(true, 'ele should be valid');
|
||||
return;
|
||||
}
|
||||
|
||||
let parentEle: HTMLElement = ele.parentElement;
|
||||
let computedStyle: any;
|
||||
|
||||
for (var i = 0; i < parentEle.children.length; i++) {
|
||||
ele = <HTMLElement>parentEle.children[i];
|
||||
|
||||
if (ele.tagName === 'ION-CONTENT') {
|
||||
let tagName: string;
|
||||
let parentEle: HTMLElement = ele.parentElement;
|
||||
let children = parentEle.children;
|
||||
for (var i = children.length - 1; i >= 0; i--) {
|
||||
ele = <HTMLElement>children[i];
|
||||
tagName = ele.tagName;
|
||||
if (tagName === 'ION-CONTENT') {
|
||||
if (this._fullscreen) {
|
||||
computedStyle = getComputedStyle(ele);
|
||||
this._paddingTop = parsePxUnit(computedStyle.paddingTop);
|
||||
@@ -507,10 +513,10 @@ export class Content extends Ion {
|
||||
this._paddingLeft = parsePxUnit(computedStyle.paddingLeft);
|
||||
}
|
||||
|
||||
} else if (ele.tagName === 'ION-HEADER') {
|
||||
} else if (tagName === 'ION-HEADER') {
|
||||
this._headerHeight = ele.clientHeight;
|
||||
|
||||
} else if (ele.tagName === 'ION-FOOTER') {
|
||||
} else if (tagName === 'ION-FOOTER') {
|
||||
this._footerHeight = ele.clientHeight;
|
||||
this._footerEle = ele;
|
||||
}
|
||||
@@ -542,11 +548,13 @@ export class Content extends Ion {
|
||||
writeDimensions() {
|
||||
let scrollEle = this._scrollEle as any;
|
||||
if (!scrollEle) {
|
||||
assert(true, 'this._scrollEle should be valid');
|
||||
return;
|
||||
}
|
||||
|
||||
let fixedEle = this._fixedEle;
|
||||
if (!fixedEle) {
|
||||
assert(true, 'this._fixedEle should be valid');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,12 @@ export class MenuContentGesture extends SlideEdgeGesture {
|
||||
let z = (this.menu.side === 'right' ? slide.min : slide.max);
|
||||
let stepValue = (slide.distance / z);
|
||||
|
||||
console.debug('menu gesture, onSlide', this.menu.side, 'distance', slide.distance, 'min', slide.min, 'max', slide.max, 'z', z, 'stepValue', stepValue);
|
||||
console.debug('menu gesture, onSlide', this.menu.side,
|
||||
'distance', slide.distance,
|
||||
'min', slide.min,
|
||||
'max', slide.max,
|
||||
'z', z,
|
||||
'stepValue', stepValue);
|
||||
|
||||
ev.preventDefault();
|
||||
this.menu.swipeProgress(stepValue);
|
||||
@@ -62,15 +67,16 @@ export class MenuContentGesture extends SlideEdgeGesture {
|
||||
let shouldCompleteLeft = (velocity <= 0)
|
||||
&& (velocity < -0.2 || slide.delta < -z);
|
||||
|
||||
console.debug('menu gesture, onSlideEnd', this.menu.side);
|
||||
console.debug('distance', slide.distance);
|
||||
console.debug('delta', slide.delta);
|
||||
console.debug('velocity', velocity);
|
||||
console.debug('min', slide.min);
|
||||
console.debug('max', slide.max);
|
||||
console.debug('shouldCompleteLeft', shouldCompleteLeft);
|
||||
console.debug('shouldCompleteRight', shouldCompleteRight);
|
||||
console.debug('currentStepValue', currentStepValue);
|
||||
console.debug('menu gesture, onSlideEnd', this.menu.side,
|
||||
'distance', slide.distance,
|
||||
'delta', slide.delta,
|
||||
'velocity', velocity,
|
||||
'min', slide.min,
|
||||
'max', slide.max,
|
||||
'shouldCompleteLeft', shouldCompleteLeft,
|
||||
'shouldCompleteRight', shouldCompleteRight,
|
||||
'currentStepValue', currentStepValue);
|
||||
|
||||
this.menu.swipeEnd(shouldCompleteLeft, shouldCompleteRight, currentStepValue);
|
||||
}
|
||||
|
||||
|
||||
@@ -245,8 +245,6 @@ export class PickerColumnCmp {
|
||||
this.velocity = 0;
|
||||
}
|
||||
|
||||
// console.debug(`decelerate y: ${y}, velocity: ${this.velocity}, optHeight: ${this.optHeight}`);
|
||||
|
||||
var notLockedIn = (y % this.optHeight !== 0 || Math.abs(this.velocity) > 1);
|
||||
|
||||
this.update(y, 0, true, !notLockedIn);
|
||||
|
||||
@@ -556,7 +556,6 @@ export class Slides extends Ion {
|
||||
ty = y-my;
|
||||
}
|
||||
|
||||
console.debug(y);
|
||||
*/
|
||||
|
||||
let zi = new Animation(this.touch.target.children[0])
|
||||
|
||||
@@ -233,11 +233,8 @@ export function populateNodeData(startCellIndex: number, endCellIndex: number, v
|
||||
};
|
||||
|
||||
totalNodes = nodes.push(availableNode);
|
||||
// console.debug(`VirtrualScroll, new node, tmpl ${cell.tmpl}, height ${cell.height}`);
|
||||
}
|
||||
|
||||
// console.debug(`node was cell ${availableNode.cell} but is now ${cellIndex}, was top: ${cell.top}`);
|
||||
|
||||
// assign who's the new cell index for this node
|
||||
availableNode.cell = cellIndex;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import { convertToView, convertToViews, NavOptions, DIRECTION_BACK, DIRECTION_FO
|
||||
import { setZIndex } from './nav-util';
|
||||
import { DeepLinker } from './deep-linker';
|
||||
import { GestureController } from '../gestures/gesture-controller';
|
||||
import { isBlank, isNumber, isPresent } from '../util/util';
|
||||
import { isBlank, isNumber, isPresent, assert } from '../util/util';
|
||||
import { isViewController, ViewController } from './view-controller';
|
||||
import { Ion } from '../components/ion';
|
||||
import { Keyboard } from '../util/keyboard';
|
||||
@@ -730,40 +730,54 @@ export class NavControllerBase extends Ion implements NavController {
|
||||
}
|
||||
|
||||
_willLoad(view: ViewController) {
|
||||
assert(this.isTransitioning(), 'nav controller should be transitioning');
|
||||
|
||||
view._willLoad();
|
||||
}
|
||||
|
||||
_didLoad(view: ViewController) {
|
||||
assert(this.isTransitioning(), 'nav controller should be transitioning');
|
||||
|
||||
view._didLoad();
|
||||
this.viewDidLoad.emit(view);
|
||||
this._app.viewDidLoad.emit(view);
|
||||
}
|
||||
|
||||
_willEnter(view: ViewController) {
|
||||
assert(this.isTransitioning(), 'nav controller should be transitioning');
|
||||
|
||||
view._willEnter();
|
||||
this.viewWillEnter.emit(view);
|
||||
this._app.viewWillEnter.emit(view);
|
||||
}
|
||||
|
||||
_didEnter(view: ViewController) {
|
||||
assert(this.isTransitioning(), 'nav controller should be transitioning');
|
||||
|
||||
view._didEnter();
|
||||
this.viewDidEnter.emit(view);
|
||||
this._app.viewDidEnter.emit(view);
|
||||
}
|
||||
|
||||
_willLeave(view: ViewController) {
|
||||
assert(this.isTransitioning(), 'nav controller should be transitioning');
|
||||
|
||||
view._willLeave();
|
||||
this.viewWillLeave.emit(view);
|
||||
this._app.viewWillLeave.emit(view);
|
||||
}
|
||||
|
||||
_didLeave(view: ViewController) {
|
||||
assert(this.isTransitioning(), 'nav controller should be transitioning');
|
||||
|
||||
view._didLeave();
|
||||
this.viewDidLeave.emit(view);
|
||||
this._app.viewDidLeave.emit(view);
|
||||
}
|
||||
|
||||
_willUnload(view: ViewController) {
|
||||
assert(this.isTransitioning(), 'nav controller should be transitioning');
|
||||
|
||||
view._willUnload();
|
||||
this.viewWillUnload.emit(view);
|
||||
this._app.viewWillUnload.emit(view);
|
||||
|
||||
@@ -155,3 +155,16 @@ export function reorderArray(array: any[], indexes: {from: number, to: number}):
|
||||
array.splice(indexes.to, 0, element);
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
function _assert(actual: any, reason?: string) {
|
||||
if (!actual) {
|
||||
let message = 'IONIC ASSERT: ' + reason;
|
||||
console.error(message);
|
||||
throw new Error(message);
|
||||
}
|
||||
}
|
||||
|
||||
export { _assert as assert};
|
||||
|
||||
Reference in New Issue
Block a user