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(ecma/parser): parse types in CallExpression
inside templates
#6611
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
104 changes: 104 additions & 0 deletions
104
crates/swc_ecma_parser/tests/typescript/issue-6601/index.tsx
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 |
---|---|---|
@@ -0,0 +1,104 @@ | ||
function exampleFunction1() { | ||
return Math.random() > 0.5 | ||
? `<button | ||
@click="${(): void => console.log('this line causes a syntax error')}" | ||
></button>` | ||
: `<button | ||
@click="${(): void => console.log('this line does NOT causes a syntax error')}" | ||
></button>`; | ||
} | ||
|
||
function exampleFunction2() { | ||
return Math.random() > 0.5 | ||
? `<bar></bar>` + `<button | ||
@click="${(): void => console.log('this line causes a syntax error')}" | ||
></button>` | ||
: `<bar></bar>` + `<button | ||
@click="${(): void => console.log('this line does NOT causes a syntax error')}" | ||
></button>`; | ||
} | ||
|
||
function exampleFunction3() { | ||
return Math.random() > 0.5 | ||
? (): void => console.log('this line causes a syntax error') | ||
: (): void => console.log('this line does NOT causes a syntax error'); | ||
} | ||
|
||
function exampleFunction4() { | ||
return Math.random() > 0.5 | ||
? function (): void { console.log('this line causes a syntax error') } | ||
: function (): void { console.log('this line does NOT causes a syntax error') }; | ||
} | ||
|
||
function exampleFunction5() { | ||
return Math.random() > 0.5 | ||
? (function (): void { console.log('this line causes a syntax error') }) | ||
: (function (): void { console.log('this line does NOT causes a syntax error') }); | ||
} | ||
|
||
function exampleFunction6() { | ||
return Math.random() > 0.5 | ||
? "test" == "test" | ||
? `<button @click="${(): void => console.log('this line causes a syntax error')}"></button>` | ||
: "bar" | ||
: `<button | ||
@click="${(): void => console.log('this line does NOT causes a syntax error')}" | ||
></button>`; | ||
} | ||
|
||
|
||
function exampleFunction6() { | ||
return Math.random() > 0.5 | ||
? `<button @click="${(): void => console.log('this line causes a syntax error')}"></button>` | ||
: "test" == "test" | ||
? `<button @click="${(): void => console.log('this line causes a syntax error')}"></button>` | ||
: "bar"; | ||
} | ||
|
||
function exampleFunction7() { | ||
return Math.random() > 0.5 | ||
? foo`<button @click="${(): void => console.log('this line causes a syntax error')}"></button>` | ||
: bar`<button @click="${(): void => console.log('this line does NOT causes a syntax error')}"></button>`; | ||
} | ||
|
||
function exampleFunction8() { | ||
return Math.random() > 0.5 | ||
? ((): void => console.log('this line causes a syntax error')) | ||
: ((): void => console.log('this line does NOT causes a syntax error')); | ||
} | ||
|
||
function exampleFunction9() { | ||
return Math.random() > 0.5 | ||
? async (): Promise<void> => console.log('this line causes a syntax error') | ||
: async (): Promise<void> => console.log('this line causes a syntax error'); | ||
} | ||
|
||
function exampleFunction10() { | ||
const foo = "Oranges"; | ||
|
||
switch (foo) { | ||
case 'Oranges': { | ||
return `<button @click="${(): void => console.log('this line causes a syntax error')}" ></button>`; | ||
} | ||
default: | ||
console.log(`Sorry, we are out of test.`); | ||
} | ||
} | ||
|
||
function exampleFunction11() { | ||
switch (true) { | ||
case ((): boolean => true)(): { | ||
console.log('This shape is a square.'); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
function exampleFunction12() { | ||
switch (((): boolean => true)()) { | ||
case ((): boolean => true)(): { | ||
console.log('This shape is a square.'); | ||
break; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need
dont_parse_colon_as_type_ann
, becausewill_expect_colon_for_cond
is used to check should we parse:
as type or not, also I found we duplicate logic, i.e. we setwill_expect_colon_for_cond
anddont_parse_colon_as_type_ann
to the same value (exceptswitch
logic, but I found it is not used there plus I added test cases)