2017-03-15 18:50:30 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
|
|
|
import './init';
|
|
|
|
import {BindingErrorComp} from '../src/errors';
|
|
|
|
import {createComponent} from './util';
|
|
|
|
|
|
|
|
describe('source maps', () => {
|
|
|
|
it('should report source location for binding errors', () => {
|
|
|
|
const comp = createComponent(BindingErrorComp);
|
|
|
|
let error: any;
|
|
|
|
try {
|
|
|
|
comp.detectChanges();
|
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
const sourcePosition = getSourcePositionForStack(error.stack);
|
|
|
|
expect(sourcePosition.line).toBe(2);
|
|
|
|
expect(sourcePosition.column).toBe(13);
|
|
|
|
expect(sourcePosition.source.endsWith('errors.html')).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function getSourcePositionForStack(stack: string): {source: string, line: number, column: number} {
|
|
|
|
const htmlLocations = stack
|
|
|
|
.split('\n')
|
|
|
|
// e.g. at View_MyComp_0 (...html:153:40)
|
2017-03-29 12:34:45 -04:00
|
|
|
.map(line => /\((.*\.html):(\d+):(\d+)/.exec(line) !)
|
2017-03-15 18:50:30 -04:00
|
|
|
.filter(match => !!match)
|
|
|
|
.map(match => ({
|
|
|
|
source: match[1],
|
|
|
|
line: parseInt(match[2], 10),
|
|
|
|
column: parseInt(match[3], 10)
|
|
|
|
}));
|
|
|
|
return htmlLocations[0];
|
|
|
|
}
|