-
Notifications
You must be signed in to change notification settings - Fork 2k
CS1 tagged template literals (and CS2 interpolated strings as template literals) #4352
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
Changes from 2 commits
4930ff1
60f64a5
772171f
94f14b5
bd2d499
bf8c5ef
85d1039
3e20728
9301274
16b37fa
51a496c
601c7a3
ec2ac5e
76d4629
9a28519
2c3374f
577444d
e8d2019
93a5e54
c87b4db
b1f9388
60819a1
3aa69fc
7248694
fe280ae
41d1631
101ee35
0f1b1f4
254d9b1
a3976f8
ee0e4a7
ee8f983
ecfe6c5
9bae435
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,91 @@ | ||
# Tagged template literals | ||
# ------------------------ | ||
|
||
func = (text) -> "I saw: #{text}" | ||
assertErrorFormat = (code, expectedErrorFormat) -> | ||
throws (-> CoffeeScript.run code), (err) -> | ||
err.colorful = no | ||
eq expectedErrorFormat, "#{err}" | ||
yes | ||
|
||
func = (text, expressions...) -> | ||
"text: [#{text.join ','}] expressions: [#{expressions.join ','}]" | ||
|
||
obj = | ||
func: func | ||
|
||
|
||
test "tagged template literals: non-interpolated strings and tag function", -> | ||
|
||
eq 'text: [single-line single quotes] expressions: []', func'single-line single quotes' | ||
|
||
eq 'text: [single-line double quotes] expressions: []', func"single-line double quotes" | ||
|
||
eq 'text: [single-line block string] expressions: []', func"""single-line block string""" | ||
|
||
eq 'text: [multi-line single quotes] expressions: []', func'multi-line | ||
single quotes' | ||
|
||
eq 'text: [multi-line double quotes] expressions: []', func"multi-line | ||
double quotes" | ||
|
||
eq 'text: [multi-line\n block string] expressions: []', func""" | ||
multi-line | ||
block string | ||
""" | ||
|
||
test "tagged template literals: string prefix must be function", -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not put these in test/error_messages.coffee? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lydell since you're around right now, are you up for a webchat about tagged template literals? I can do Skype on my github username, or Google Hangouts on ghuczynski at gmail.com I'm working on tagged template literals today Sunday, and I'd appreciate talking to someone with more CS compiler knowledge than me! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’m sorry, I won’t have the time. |
||
|
||
assertErrorFormat "nofunc''", 'ReferenceError: nofunc is not defined' | ||
|
||
assertErrorFormat "1''", ''' | ||
[stdin]:1:2: error: unexpected string | ||
1'' | ||
^^ | ||
''' | ||
|
||
assertErrorFormat "[1]''", ''' | ||
[stdin]:1:4: error: unexpected string | ||
[1]'' | ||
^^ | ||
''' | ||
|
||
# TODO: implement this case | ||
#test "tagged template literals: non-interpolated strings and tag property function", -> | ||
# | ||
# eq 'text: [single-line single quotes] expressions: []', obj.func'single-line single quotes' | ||
# | ||
# eq 'text: [single-line double quotes] expressions: []', obj.func"single-line double quotes" | ||
# | ||
# eq 'text: [single-line block string] expressions: []', obj.func"""single-line block string""" | ||
# | ||
# eq 'text: [multi-line single quotes] expressions: []', obj.func'multi-line | ||
# single quotes' | ||
# | ||
# eq 'text: [multi-line double quotes] expressions: []', obj.func"multi-line | ||
# double quotes" | ||
# | ||
# eq 'text: [multi-line\n block string] expressions: []', obj.func""" | ||
# multi-line | ||
# block string | ||
# """ | ||
|
||
# TODO: implement this case | ||
test "tagged template literals: interpolated strings and tag function", -> | ||
# TODO: single-line single quotes | ||
# TODO: single-line double quotes | ||
# TODO: single-line block string | ||
# TODO: multi-line single quotes | ||
# TODO: multi-line double quotes | ||
# TODO: multi-line block string | ||
|
||
# TODO: implement this case | ||
test "tagged template literals: interpolated strings and tag property function", -> | ||
# TODO: single-line single quotes | ||
# TODO: single-line double quotes | ||
# TODO: single-line block string | ||
# TODO: multi-line single quotes | ||
# TODO: multi-line double quotes | ||
# TODO: multi-line block string | ||
|
||
|
||
|
||
eq 'I saw: a single line string', func'a single line string' | ||
eq 'I saw: a multi line string', func'a multi line | ||
string' |
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.
Please avoid this kind of crazy indentation :)