-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(compiler): assert doesn't work with string interpolation (#3038)
Fixes #1833 The high level idea behind this fix is to avoid using backtick-strings in our generated JavaScript. These lead to a lot of issues that can be avoided by using other concatenation strategies that do not introduce grammar complexities. In this case, I decided to use `String.raw()`, but translating interpolated strings into a sequence of `+` operations probably could have worked too. The other major change I did was improving the errors emitted by `assert()` so that it shows the original Wing source code that you asserted, not the emitted JavaScript. For example, now an error looks like: ``` assertion failed: b.list().length == 1 ``` instead of: ``` assertion failed: '((await b.list()).length === 1)' ``` ## Checklist - [x] Title matches [Winglang's style guide](https://docs.winglang.io/contributors/pull_requests#how-are-pull-request-titles-formatted) - [x] Description explains motivation and solution - [x] Tests added (always) - [ ] Docs updated (only required for features) - [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing *By submitting this pull request, I confirm that my contribution is made under the terms of the [Monada Contribution License](https://docs.winglang.io/terms-and-policies/contribution-license.html)*.
- Loading branch information
Showing
122 changed files
with
1,325 additions
and
927 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
let s1 = "foo"; | ||
let s2 = "bar"; | ||
|
||
assert("" == ""); | ||
assert("'" == "'"); | ||
assert("\"" == "\""); | ||
assert("`" == "`"); | ||
assert("``" == "``"); | ||
assert("`s1`" == "`s1`"); | ||
assert(s1 == s1); | ||
assert("${s1}" == "${s1}"); | ||
assert("${s1}" != "${s2}"); | ||
assert("a${s1}" == "a${s1}"); | ||
assert("a${s1}" != "b${s1}"); | ||
assert("${s1}a" == "${s1}a"); | ||
assert("${s1}a" != "${s1}b"); | ||
assert("`'${s1}" == "`'${s1}"); | ||
assert("a${s1}b${s2}c" == "a${s1}b${s2}c"); | ||
|
||
test "assert works inflight" { | ||
assert("" == ""); | ||
assert("'" == "'"); | ||
assert("\"" == "\""); | ||
assert("`" == "`"); | ||
assert("``" == "``"); | ||
assert("`s1`" == "`s1`"); | ||
assert(s1 == s1); | ||
assert("${s1}" == "${s1}"); | ||
assert("${s1}" != "${s2}"); | ||
assert("a${s1}" == "a${s1}"); | ||
assert("a${s1}" != "b${s1}"); | ||
assert("${s1}a" == "${s1}a"); | ||
assert("${s1}a" != "${s1}b"); | ||
assert("`'${s1}" == "`'${s1}"); | ||
assert("a${s1}b${s2}c" == "a${s1}b${s2}c"); | ||
} |
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
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
Oops, something went wrong.