"Fossies" - the Fresh Open Source Software Archive

Member "angular-13.3.10/packages/compiler-cli/ngcc/test/packages/adjust_cjs_exports_spec.ts" (25 May 2022, 1693 Bytes) of package /linux/www/angular-13.3.10.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 import {adjustElementAccessExports} from '../../src/packages/adjust_cjs_umd_exports';
    9 
   10 describe('adjustElementAccessExports', () => {
   11   it('should replace exports using element access syntax', () => {
   12     expectChanged(`exports['Foo']`, `exports. Foo  `);
   13     expectChanged(
   14         `exports['Foo']; exports['Bar']; exports['Baz'];`,
   15         `exports. Foo  ; exports. Bar  ; exports. Baz  ;`);
   16     expectChanged(
   17         `function(exports) { exports['Foo'] = Foo; }`,
   18         `function(exports) { exports. Foo   = Foo; }`);
   19     expectChanged(
   20         `function(exports) { exports['ɵFoo'] = Foo; }`,
   21         `function(exports) { exports. ɵFoo   = Foo; }`);
   22   });
   23 
   24   it('should not replace invalid identifier names', () => {
   25     expectUnchanged(`exports['']`);
   26     expectUnchanged(`exports['let']`);
   27     expectUnchanged(`exports['var']`);
   28     expectUnchanged(`exports['const']`);
   29   });
   30 
   31   it('should not replace export syntax in comments and strings', () => {
   32     expectUnchanged(`/* exports['Foo'] = Foo; */`);
   33     expectUnchanged(`"exports['Foo'] = Foo;"`);
   34     expectChanged(
   35         `/* exports['Foo'] = Foo; */ exports['Foo'] = Foo;`,
   36         `/* exports['Foo'] = Foo; */ exports. Foo   = Foo;`);
   37   });
   38 });
   39 
   40 function expectChanged(input: string, expected: string) {
   41   const result = adjustElementAccessExports(input);
   42   expect(result).toEqual(expected);
   43 }
   44 
   45 function expectUnchanged(input: string) {
   46   const result = adjustElementAccessExports(input);
   47   expect(result).toEqual(input);
   48 }