Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): migrate relative link resolution with single quotes #39102

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'`));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it might be a good idea to leave a comment about why we use createIdentifier here.

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