2016-06-23 12:47:54 -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
|
|
|
|
*/
|
|
|
|
|
2016-08-26 18:54:34 -04:00
|
|
|
import {escapeIdentifier} from '@angular/compiler/src/output/abstract_emitter';
|
2016-01-06 17:13:44 -05:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('AbstractEmitter', () => {
|
2016-08-26 18:54:34 -04:00
|
|
|
describe('escapeIdentifier', () => {
|
2016-01-06 17:13:44 -05:00
|
|
|
it('should escape single quotes',
|
2016-08-26 18:54:34 -04:00
|
|
|
() => { expect(escapeIdentifier(`'`, false)).toEqual(`'\\''`); });
|
2016-01-06 17:13:44 -05:00
|
|
|
|
|
|
|
it('should escape backslash',
|
2016-08-26 18:54:34 -04:00
|
|
|
() => { expect(escapeIdentifier('\\', false)).toEqual(`'\\\\'`); });
|
2016-01-06 17:13:44 -05:00
|
|
|
|
|
|
|
it('should escape newlines',
|
2016-08-26 18:54:34 -04:00
|
|
|
() => { expect(escapeIdentifier('\n', false)).toEqual(`'\\n'`); });
|
2016-01-06 17:13:44 -05:00
|
|
|
|
|
|
|
it('should escape carriage returns',
|
2016-08-26 18:54:34 -04:00
|
|
|
() => { expect(escapeIdentifier('\r', false)).toEqual(`'\\r'`); });
|
2016-01-06 17:13:44 -05:00
|
|
|
|
2016-08-26 18:54:34 -04:00
|
|
|
it('should escape $', () => { expect(escapeIdentifier('$', true)).toEqual(`'\\$'`); });
|
|
|
|
it('should not escape $', () => { expect(escapeIdentifier('$', false)).toEqual(`'$'`); });
|
|
|
|
it('should add quotes for non-identifiers',
|
|
|
|
() => { expect(escapeIdentifier('==', false, false)).toEqual(`'=='`); });
|
|
|
|
it('does not escape class (but it probably should)',
|
|
|
|
() => { expect(escapeIdentifier('class', false, false)).toEqual('class'); });
|
2016-01-06 17:13:44 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2017-01-27 17:23:12 -05:00
|
|
|
|
|
|
|
export function stripSourceMap(source: string): string {
|
|
|
|
const smi = source.lastIndexOf('\n//#');
|
|
|
|
if (smi == -1) return source;
|
|
|
|
return source.slice(0, smi);
|
|
|
|
}
|