From 3a6ba002867080ebf5199ed825d7bd7bbb4918fe Mon Sep 17 00:00:00 2001 From: Alex Rickabaugh Date: Fri, 8 Mar 2019 14:03:49 -0800 Subject: [PATCH] fix(ivy): escape all required characters in reexport aliases (#29194) Previously, the compiler did not escape . or $, and this was causing issues in google3. Now these characters are escaped. PR Close #29194 --- .../src/ngtsc/imports/src/alias.ts | 4 +-- .../compiler-cli/test/ngtsc/ngtsc_spec.ts | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/packages/compiler-cli/src/ngtsc/imports/src/alias.ts b/packages/compiler-cli/src/ngtsc/imports/src/alias.ts index 89b2e54b83..b7231f7faa 100644 --- a/packages/compiler-cli/src/ngtsc/imports/src/alias.ts +++ b/packages/compiler-cli/src/ngtsc/imports/src/alias.ts @@ -12,8 +12,8 @@ import * as ts from 'typescript'; import {FileToModuleHost, ReferenceEmitStrategy} from './emitter'; import {ImportMode, Reference} from './references'; -// Escape anything that isn't alphanumeric, '/', '_', '.', or '$'. -const CHARS_TO_ESCAPE = /[^a-zA-Z0-9/_\.$]/g; +// Escape anything that isn't alphanumeric, '/' or '_'. +const CHARS_TO_ESCAPE = /[^a-zA-Z0-9/_]/g; export class AliasGenerator { constructor(private fileToModuleHost: FileToModuleHost) {} diff --git a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts index f3545e0abc..30d1ff7078 100644 --- a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts +++ b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts @@ -3565,6 +3565,36 @@ export const Foo = Foo__PRE_R3__; const jsContents = env.getContents('index.js'); expect(jsContents).toContain('export { FooDir as ɵng$root$foo$$FooDir } from "root/foo";'); }); + + it('should escape unusual characters in aliased filenames', () => { + env.tsconfig({'_useHostForImportGeneration': true}); + env.write('other._$test.ts', ` + import {Directive, NgModule} from '@angular/core'; + + @Directive({selector: 'test'}) + export class TestDir {} + + @NgModule({ + declarations: [TestDir], + exports: [TestDir], + }) + export class OtherModule {} + `); + env.write('index.ts', ` + import {NgModule} from '@angular/core'; + import {OtherModule} from './other._$test'; + + @NgModule({ + exports: [OtherModule], + }) + export class IndexModule {} + `); + env.driveMain(); + const jsContents = env.getContents('index.js'); + expect(jsContents) + .toContain( + 'export { TestDir as ɵng$root$other___test$$TestDir } from "root/other._$test";'); + }); }); describe('inline resources', () => {