Skip to content

Commit

Permalink
fix(core): migrate relative link resolution with single quotes (#39102)
Browse files Browse the repository at this point in the history
This is a roll forward of #39082, using `ts.createIdentifier(`'legacy'`)` as a cross-version compatible way of making
a single quoted string literal.

Migrated code now uses single quotes, which is in line with the default linting options, so there is no lint error after
migration.

PR Close #39102
  • Loading branch information
dgp1130 authored and atscott committed Oct 8, 2020
1 parent dace4aa commit 049b453
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class RelativeLinkResolutionTransform {
return literal;
}
const legacyExpression =
ts.createPropertyAssignment(RELATIVE_LINK_RESOLUTION, ts.createStringLiteral('legacy'));
ts.createPropertyAssignment(RELATIVE_LINK_RESOLUTION, ts.createIdentifier(`'legacy'`));
return ts.updateObjectLiteral(literal, [...literal.properties, legacyExpression]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('Google3 relativeLinkResolution TSLint rule', () => {

runTSLint(true);
expect(getFile('/index.ts'))
.toContain(`RouterModule.forRoot([], { relativeLinkResolution: "legacy" })`);
.toContain(`RouterModule.forRoot([], { relativeLinkResolution: 'legacy' })`);
});

it('should migrate options without relativeLinkResolution', () => {
Expand All @@ -103,7 +103,7 @@ describe('Google3 relativeLinkResolution TSLint rule', () => {

runTSLint(true);
expect(getFile('/index.ts'))
.toContain(`RouterModule.forRoot([], { useHash: true, relativeLinkResolution: "legacy" })`);
.toContain(`RouterModule.forRoot([], { useHash: true, relativeLinkResolution: 'legacy' })`);
});

it('should not migrate options containing relativeLinkResolution', () => {
Expand Down Expand Up @@ -133,7 +133,7 @@ describe('Google3 relativeLinkResolution TSLint rule', () => {
runTSLint(true);
expect(getFile('/index.ts'))
.toContain(
`const options = { useHash: true, relativeLinkResolution: "legacy" } as ExtraOptions;`);
`const options = { useHash: true, relativeLinkResolution: 'legacy' } as ExtraOptions;`);
});

it('should migrate when options is a variable', () => {
Expand All @@ -145,7 +145,7 @@ describe('Google3 relativeLinkResolution TSLint rule', () => {
runTSLint(true);
expect(getFile('/index.ts'))
.toContain(
`const options: ExtraOptions = { useHash: true, relativeLinkResolution: "legacy" };`);
`const options: ExtraOptions = { useHash: true, relativeLinkResolution: 'legacy' };`);
});

it('should migrate when options is a variable with no type', () => {
Expand All @@ -166,7 +166,7 @@ describe('Google3 relativeLinkResolution TSLint rule', () => {

runTSLint(true);
expect(getFile('/index.ts'))
.toContain(`const options = { useHash: true, relativeLinkResolution: "legacy" };`);
.toContain(`const options = { useHash: true, relativeLinkResolution: 'legacy' };`);
expect(getFile('/index.ts')).toContain(`RouterModule.forRoot([], options)`);
});

Expand All @@ -179,7 +179,7 @@ describe('Google3 relativeLinkResolution TSLint rule', () => {
runTSLint(true);
expect(getFile('/index.ts'))
.toContain(
`const options: RouterExtraOptions = { useHash: true, relativeLinkResolution: "legacy" };`);
`const options: RouterExtraOptions = { useHash: true, relativeLinkResolution: 'legacy' };`);
});

it('should migrate aliased RouterModule.forRoot', () => {
Expand All @@ -197,6 +197,6 @@ describe('Google3 relativeLinkResolution TSLint rule', () => {

runTSLint(true);
expect(getFile('/index.ts'))
.toContain(`AngularRouterModule.forRoot([], { relativeLinkResolution: "legacy" }),`);
.toContain(`AngularRouterModule.forRoot([], { relativeLinkResolution: 'legacy' }),`);
});
});
14 changes: 7 additions & 7 deletions packages/core/schematics/test/relative_link_resolution_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('initial navigation migration', () => {

await runMigration();
expect(tree.readContent('/index.ts'))
.toContain(`RouterModule.forRoot([], { relativeLinkResolution: "legacy" })`);
.toContain(`RouterModule.forRoot([], { relativeLinkResolution: 'legacy' })`);
});

it('should migrate options without relativeLinkResolution', async () => {
Expand All @@ -79,7 +79,7 @@ describe('initial navigation migration', () => {

await runMigration();
expect(tree.readContent('/index.ts'))
.toContain(`RouterModule.forRoot([], { useHash: true, relativeLinkResolution: "legacy" })`);
.toContain(`RouterModule.forRoot([], { useHash: true, relativeLinkResolution: 'legacy' })`);
});

it('should not migrate options containing relativeLinkResolution', async () => {
Expand Down Expand Up @@ -109,7 +109,7 @@ describe('initial navigation migration', () => {
await runMigration();
expect(tree.readContent('/index.ts'))
.toContain(
`const options = { useHash: true, relativeLinkResolution: "legacy" } as ExtraOptions;`);
`const options = { useHash: true, relativeLinkResolution: 'legacy' } as ExtraOptions;`);
});

it('should migrate when options is a variable', async () => {
Expand All @@ -121,7 +121,7 @@ describe('initial navigation migration', () => {
await runMigration();
expect(tree.readContent('/index.ts'))
.toContain(
`const options: ExtraOptions = { useHash: true, relativeLinkResolution: "legacy" };`);
`const options: ExtraOptions = { useHash: true, relativeLinkResolution: 'legacy' };`);
});

it('should migrate when options is a variable with no type', async () => {
Expand All @@ -142,7 +142,7 @@ describe('initial navigation migration', () => {

await runMigration();
expect(tree.readContent('/index.ts'))
.toContain(`const options = { useHash: true, relativeLinkResolution: "legacy" };`);
.toContain(`const options = { useHash: true, relativeLinkResolution: 'legacy' };`);
expect(tree.readContent('/index.ts')).toContain(`RouterModule.forRoot([], options)`);
});

Expand All @@ -155,7 +155,7 @@ describe('initial navigation migration', () => {
await runMigration();
expect(tree.readContent('/index.ts'))
.toContain(
`const options: RouterExtraOptions = { useHash: true, relativeLinkResolution: "legacy" };`);
`const options: RouterExtraOptions = { useHash: true, relativeLinkResolution: 'legacy' };`);
});

it('should migrate aliased RouterModule.forRoot', async () => {
Expand All @@ -173,7 +173,7 @@ describe('initial navigation migration', () => {

await runMigration();
expect(tree.readContent('/index.ts'))
.toContain(`AngularRouterModule.forRoot([], { relativeLinkResolution: "legacy" }),`);
.toContain(`AngularRouterModule.forRoot([], { relativeLinkResolution: 'legacy' }),`);
});

function writeFile(filePath: string, contents: string) {
Expand Down

0 comments on commit 049b453

Please sign in to comment.