2016-06-23 12:47:54 -04:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2016-06-23 12:47:54 -04:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
2017-12-16 17:42:55 -05:00
|
|
|
{
|
2016-01-06 17:13:44 -05:00
|
|
|
describe('AbstractEmitter', () => {
|
2016-08-26 18:54:34 -04:00
|
|
|
describe('escapeIdentifier', () => {
|
2020-04-08 13:14:18 -04:00
|
|
|
it('should escape single quotes', () => {
|
|
|
|
expect(escapeIdentifier(`'`, false)).toEqual(`'\\''`);
|
|
|
|
});
|
2016-01-06 17:13:44 -05:00
|
|
|
|
2020-04-08 13:14:18 -04:00
|
|
|
it('should escape backslash', () => {
|
|
|
|
expect(escapeIdentifier('\\', false)).toEqual(`'\\\\'`);
|
|
|
|
});
|
2016-01-06 17:13:44 -05:00
|
|
|
|
2020-04-08 13:14:18 -04:00
|
|
|
it('should escape newlines', () => {
|
|
|
|
expect(escapeIdentifier('\n', false)).toEqual(`'\\n'`);
|
|
|
|
});
|
2016-01-06 17:13:44 -05:00
|
|
|
|
2020-04-08 13:14:18 -04:00
|
|
|
it('should escape carriage returns', () => {
|
|
|
|
expect(escapeIdentifier('\r', false)).toEqual(`'\\r'`);
|
|
|
|
});
|
2016-01-06 17:13:44 -05:00
|
|
|
|
2020-04-08 13:14:18 -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
|
|
|
|
2017-03-14 12:16:15 -04:00
|
|
|
export function stripSourceMapAndNewLine(source: string): string {
|
|
|
|
if (source.endsWith('\n')) {
|
|
|
|
source = source.substring(0, source.length - 1);
|
|
|
|
}
|
2017-01-27 17:23:12 -05:00
|
|
|
const smi = source.lastIndexOf('\n//#');
|
|
|
|
if (smi == -1) return source;
|
|
|
|
return source.slice(0, smi);
|
2020-05-19 15:08:49 -04:00
|
|
|
}
|