-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented non-null, optional chaining and nullish coalescing operators
- Loading branch information
Andrii Rodionov
committed
Nov 13, 2024
1 parent
ac916bb
commit a55ccda
Showing
6 changed files
with
136 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 66 additions & 12 deletions
78
openrewrite/test/javascript/parser/expressionStatement.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,80 @@ | ||
import {connect, disconnect, rewriteRunWithOptions, typeScript} from '../testHarness'; | ||
import {connect, disconnect, rewriteRun, rewriteRunWithOptions, typeScript} from '../testHarness'; | ||
|
||
describe('expression statement mapping', () => { | ||
beforeAll(() => connect()); | ||
afterAll(() => disconnect()); | ||
|
||
test('literal with semicolon', () => { | ||
rewriteRunWithOptions( | ||
{normalizeIndent: false}, | ||
typeScript('1 ;') | ||
{normalizeIndent: false}, | ||
typeScript('1 ;') | ||
); | ||
}); | ||
test('multiple', () => { | ||
rewriteRunWithOptions( | ||
{normalizeIndent: false}, | ||
typeScript( | ||
//language=ts | ||
` | ||
1; // foo | ||
// bar | ||
/*baz*/ | ||
2;` | ||
) | ||
{normalizeIndent: false}, | ||
typeScript( | ||
//language=ts | ||
` | ||
1; // foo | ||
// bar | ||
/*baz*/ | ||
2;` | ||
) | ||
); | ||
}); | ||
|
||
test('simple non-null expression', () => { | ||
rewriteRun( | ||
//language=typescript | ||
typeScript(` | ||
const length = user ! . profile ! . username ! . length ; | ||
`) | ||
); | ||
}); | ||
|
||
test('simple question-dot expression', () => { | ||
rewriteRun( | ||
//language=typescript | ||
typeScript(` | ||
const length = user ?. profile ?. username ?. length ; | ||
`) | ||
); | ||
}); | ||
|
||
test('simple default expression', () => { | ||
rewriteRun( | ||
//language=typescript | ||
typeScript(` | ||
const length = user ?? 'default' ; | ||
`) | ||
); | ||
}); | ||
|
||
test('mixed expression with special tokens', () => { | ||
rewriteRun( | ||
//language=typescript | ||
typeScript(` | ||
class Profile { | ||
username?: string; // Optional property | ||
} | ||
class User { | ||
profile?: Profile; // Optional property | ||
} | ||
function getUser(id: number) : User | null { | ||
if (id === 1) { | ||
return new User(); | ||
} | ||
return null; | ||
} | ||
const user = getUser(1); | ||
const length = user ! . profile ?. username !. length /*test*/ ; | ||
const username2 = getUser(1) ! . profile ?. username ; // test; | ||
const username = user!.profile?.username ?? 'Guest' ; | ||
`) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters