mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
a3fb4a5f70
Cleans up the `escapeDollarInStrings` parameter in various places since it isn't passed anywhere.
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC 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.dev/license
|
|
*/
|
|
|
|
import {escapeIdentifier} from '../../src/output/abstract_emitter';
|
|
|
|
describe('AbstractEmitter', () => {
|
|
describe('escapeIdentifier', () => {
|
|
it('should escape single quotes', () => {
|
|
expect(escapeIdentifier(`'`)).toEqual(`'\\''`);
|
|
});
|
|
|
|
it('should escape backslash', () => {
|
|
expect(escapeIdentifier('\\')).toEqual(`'\\\\'`);
|
|
});
|
|
|
|
it('should escape newlines', () => {
|
|
expect(escapeIdentifier('\n')).toEqual(`'\\n'`);
|
|
});
|
|
|
|
it('should escape carriage returns', () => {
|
|
expect(escapeIdentifier('\r')).toEqual(`'\\r'`);
|
|
});
|
|
|
|
it('should add quotes for non-identifiers', () => {
|
|
expect(escapeIdentifier('==', false)).toEqual(`'=='`);
|
|
});
|
|
it('does not escape class (but it probably should)', () => {
|
|
expect(escapeIdentifier('class', false)).toEqual('class');
|
|
});
|
|
});
|
|
});
|
|
|
|
export function stripSourceMapAndNewLine(source: string): string {
|
|
if (source.endsWith('\n')) {
|
|
source = source.substring(0, source.length - 1);
|
|
}
|
|
const smi = source.lastIndexOf('\n//#');
|
|
if (smi == -1) return source;
|
|
return source.slice(0, smi);
|
|
}
|