Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 3c5c266

Browse files
committed
refactor(deep-linking): update deep-linking parsing to use TS 2.3.x api
1 parent b766037 commit 3c5c266

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/deep-linking/util.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ describe('util', () => {
4343
fileCache.set(pageThreeModule, { path: pageThreeModule, content: knownFileContent});
4444
fileCache.set(someOtherFile, { path: someOtherFile, content: knownFileContent});
4545

46-
spyOn(helpers, helpers.getStringPropertyValue.name).and.returnValues(pagesDir, '.module.ts');
46+
spyOn(helpers, helpers.getStringPropertyValue.name).and.callFake((input: string) => {
47+
if (input === Constants.ENV_VAR_DEEPLINKS_DIR) {
48+
return pagesDir;
49+
}
50+
return '.module.ts';
51+
});
4752

4853
const results = util.filterTypescriptFilesForDeepLinks(fileCache);
4954
expect(results.length).toEqual(3);

src/deep-linking/util.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,14 @@ export function getDeepLinkData(appNgModuleFilePath: string, fileCache: FileCach
8484
}
8585

8686
export function filterTypescriptFilesForDeepLinks(fileCache: FileCache): File[] {
87+
return fileCache.getAll().filter(file => isDeepLinkingFile(file.path));
88+
}
89+
90+
export function isDeepLinkingFile(filePath: string) {
8791
const deepLinksDir = getStringPropertyValue(Constants.ENV_VAR_DEEPLINKS_DIR);
8892
const moduleSuffix = getStringPropertyValue(Constants.ENV_NG_MODULE_FILE_NAME_SUFFIX);
89-
return fileCache.getAll().filter(file => extname(file.path) === '.ts' && file.path.indexOf(moduleSuffix) === -1 && file.path.indexOf(deepLinksDir) >= 0);
93+
const result = extname(filePath) === '.ts' && filePath.indexOf(moduleSuffix) === -1 && filePath.indexOf(deepLinksDir) >= 0;
94+
return result;
9095
}
9196

9297
export function getNgModulePathFromCorrespondingPage(filePath: string) {
@@ -390,7 +395,7 @@ export function purgeDeepLinkDecoratorTSTransformImpl(transformContext: Transfor
390395
const diffDecorators: Decorator[] = [];
391396
for (const decorator of classDeclaration.decorators || []) {
392397
if (decorator.expression && (decorator.expression as CallExpression).expression
393-
&& ((decorator.expression as CallExpression).expression as Identifier).escapedText === DEEPLINK_DECORATOR_TEXT) {
398+
&& ((decorator.expression as CallExpression).expression as Identifier).text === DEEPLINK_DECORATOR_TEXT) {
394399
hasDeepLinkDecorator = true;
395400
} else {
396401
diffDecorators.push(decorator);
@@ -425,7 +430,7 @@ export function purgeDeepLinkDecoratorTSTransformImpl(transformContext: Transfor
425430
const importSpecifiers: ImportSpecifier[] = [];
426431
(importDeclaration.importClause.namedBindings as NamedImports).elements.forEach((importSpecifier: ImportSpecifier) => {
427432

428-
if (importSpecifier.name.escapedText !== DEEPLINK_DECORATOR_TEXT) {
433+
if (importSpecifier.name.text !== DEEPLINK_DECORATOR_TEXT) {
429434
importSpecifiers.push(importSpecifier);
430435
}
431436
});
@@ -441,7 +446,6 @@ export function purgeDeepLinkDecoratorTSTransformImpl(transformContext: Transfor
441446
);
442447
}
443448

444-
445449
return importDeclaration;
446450
}
447451

@@ -473,7 +477,7 @@ export function purgeDeepLinkDecorator(inputText: string): string {
473477
for (const classDeclaration of classDeclarations) {
474478
for (const decorator of classDeclaration.decorators || []) {
475479
if (decorator.expression && (decorator.expression as CallExpression).expression
476-
&& ((decorator.expression as CallExpression).expression as Identifier).escapedText === DEEPLINK_DECORATOR_TEXT) {
480+
&& ((decorator.expression as CallExpression).expression as Identifier).text === DEEPLINK_DECORATOR_TEXT) {
477481
toRemove.push(decorator);
478482
}
479483
}
@@ -502,10 +506,10 @@ export function purgeDeepLinkImport(inputText: string): string {
502506
const namedImportStrings: string[] = [];
503507
(importDeclaration.importClause.namedBindings as NamedImports).elements.forEach((importSpecifier: ImportSpecifier) => {
504508

505-
if (importSpecifier.name.escapedText === DEEPLINK_DECORATOR_TEXT) {
509+
if (importSpecifier.name.text === DEEPLINK_DECORATOR_TEXT) {
506510
decoratorIsImported = true;
507511
} else {
508-
namedImportStrings.push(importSpecifier.name.escapedText as string);
512+
namedImportStrings.push(importSpecifier.name.text as string);
509513
}
510514
});
511515

@@ -530,14 +534,14 @@ export function purgeDeepLinkImport(inputText: string): string {
530534

531535
export function getInjectDeepLinkConfigTypescriptTransform() {
532536
const deepLinkString = convertDeepLinkConfigEntriesToString(getParsedDeepLinkConfig());
533-
const appNgModulePath = getStringPropertyValue(Constants.ENV_APP_NG_MODULE_PATH);
537+
const appNgModulePath = toUnixPath(getStringPropertyValue(Constants.ENV_APP_NG_MODULE_PATH));
534538
return injectDeepLinkConfigTypescriptTransform(deepLinkString, appNgModulePath);
535539
}
536540

537541
export function injectDeepLinkConfigTypescriptTransform(deepLinkString: string, appNgModuleFilePath: string): TransformerFactory<SourceFile> {
538542

539543
function visitDecoratorNode(decorator: Decorator, sourceFile: SourceFile): Decorator {
540-
if (decorator.expression && (decorator.expression as CallExpression).expression && ((decorator.expression as CallExpression).expression as Identifier).escapedText === NG_MODULE_DECORATOR_TEXT) {
544+
if (decorator.expression && (decorator.expression as CallExpression).expression && ((decorator.expression as CallExpression).expression as Identifier).text === NG_MODULE_DECORATOR_TEXT) {
541545

542546
// okay cool, we have the ng module
543547
let functionCall = getIonicModuleForRootCall(decorator);

0 commit comments

Comments
 (0)