"Fossies" - the Fresh Open Source Software Archive

Member "angular-13.3.9/packages/compiler/test/output/abstract_emitter_spec.ts" (18 May 2022, 1639 Bytes) of package /linux/www/angular-13.3.9.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /**
    2  * @license
    3  * Copyright Google LLC All Rights Reserved.
    4  *
    5  * Use of this source code is governed by an MIT-style license that can be
    6  * found in the LICENSE file at https://angular.io/license
    7  */
    8 
    9 import {escapeIdentifier} from '@angular/compiler/src/output/abstract_emitter';
   10 
   11 {
   12   describe('AbstractEmitter', () => {
   13     describe('escapeIdentifier', () => {
   14       it('should escape single quotes', () => {
   15         expect(escapeIdentifier(`'`, false)).toEqual(`'\\''`);
   16       });
   17 
   18       it('should escape backslash', () => {
   19         expect(escapeIdentifier('\\', false)).toEqual(`'\\\\'`);
   20       });
   21 
   22       it('should escape newlines', () => {
   23         expect(escapeIdentifier('\n', false)).toEqual(`'\\n'`);
   24       });
   25 
   26       it('should escape carriage returns', () => {
   27         expect(escapeIdentifier('\r', false)).toEqual(`'\\r'`);
   28       });
   29 
   30       it('should escape $', () => {
   31         expect(escapeIdentifier('$', true)).toEqual(`'\\$'`);
   32       });
   33       it('should not escape $', () => {
   34         expect(escapeIdentifier('$', false)).toEqual(`'$'`);
   35       });
   36       it('should add quotes for non-identifiers', () => {
   37         expect(escapeIdentifier('==', false, false)).toEqual(`'=='`);
   38       });
   39       it('does not escape class (but it probably should)', () => {
   40         expect(escapeIdentifier('class', false, false)).toEqual('class');
   41       });
   42     });
   43   });
   44 }
   45 
   46 export function stripSourceMapAndNewLine(source: string): string {
   47   if (source.endsWith('\n')) {
   48     source = source.substring(0, source.length - 1);
   49   }
   50   const smi = source.lastIndexOf('\n//#');
   51   if (smi == -1) return source;
   52   return source.slice(0, smi);
   53 }