2016-07-24 23:37:37 -04:00
|
|
|
# Error Formatting
|
|
|
|
# ----------------
|
2013-02-25 23:30:23 -05:00
|
|
|
|
|
|
|
# Ensure that errors of different kinds (lexer, parser and compiler) are shown
|
|
|
|
# in a consistent way.
|
|
|
|
|
|
|
|
assertErrorFormat = (code, expectedErrorFormat) ->
|
2013-03-21 02:11:31 -04:00
|
|
|
throws (-> CoffeeScript.run code), (err) ->
|
2013-07-31 07:27:49 -04:00
|
|
|
err.colorful = no
|
|
|
|
eq expectedErrorFormat, "#{err}"
|
2013-02-25 23:30:23 -05:00
|
|
|
yes
|
|
|
|
|
2016-07-24 23:37:37 -04:00
|
|
|
test "lexer errors formatting", ->
|
2013-02-25 23:30:23 -05:00
|
|
|
assertErrorFormat '''
|
|
|
|
normalObject = {}
|
|
|
|
insideOutObject = }{
|
|
|
|
''',
|
|
|
|
'''
|
2013-07-31 07:27:49 -04:00
|
|
|
[stdin]:2:19: error: unmatched }
|
2013-02-25 23:30:23 -05:00
|
|
|
insideOutObject = }{
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
|
2016-07-24 23:37:37 -04:00
|
|
|
test "parser error formatting", ->
|
2013-02-25 23:30:23 -05:00
|
|
|
assertErrorFormat '''
|
|
|
|
foo in bar or in baz
|
|
|
|
''',
|
|
|
|
'''
|
2014-01-21 21:44:50 -05:00
|
|
|
[stdin]:1:15: error: unexpected in
|
2013-02-25 23:30:23 -05:00
|
|
|
foo in bar or in baz
|
|
|
|
^^
|
|
|
|
'''
|
|
|
|
|
|
|
|
test "compiler error formatting", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
evil = (foo, eval, bar) ->
|
|
|
|
''',
|
|
|
|
'''
|
2016-03-05 14:59:39 -05:00
|
|
|
[stdin]:1:14: error: 'eval' can't be assigned
|
2013-02-25 23:30:23 -05:00
|
|
|
evil = (foo, eval, bar) ->
|
|
|
|
^^^^
|
2013-03-21 02:11:31 -04:00
|
|
|
'''
|
|
|
|
|
2014-01-27 11:55:20 -05:00
|
|
|
if require?
|
|
|
|
fs = require 'fs'
|
|
|
|
path = require 'path'
|
2013-03-21 02:11:31 -04:00
|
|
|
|
2014-01-27 11:55:20 -05:00
|
|
|
test "patchStackTrace line patching", ->
|
|
|
|
err = new Error 'error'
|
|
|
|
ok err.stack.match /test[\/\\]error_messages\.coffee:\d+:\d+\b/
|
2013-03-21 02:11:31 -04:00
|
|
|
|
2014-02-07 07:01:01 -05:00
|
|
|
test "patchStackTrace stack prelude consistent with V8", ->
|
|
|
|
err = new Error
|
|
|
|
ok err.stack.match /^Error\n/ # Notice no colon when no message.
|
|
|
|
|
|
|
|
err = new Error 'error'
|
|
|
|
ok err.stack.match /^Error: error\n/
|
|
|
|
|
2014-01-27 11:55:20 -05:00
|
|
|
test "#2849: compilation error in a require()d file", ->
|
|
|
|
# Create a temporary file to require().
|
|
|
|
ok not fs.existsSync 'test/syntax-error.coffee'
|
|
|
|
fs.writeFileSync 'test/syntax-error.coffee', 'foo in bar or in baz'
|
2014-02-07 07:01:01 -05:00
|
|
|
|
2014-01-27 11:55:20 -05:00
|
|
|
try
|
|
|
|
assertErrorFormat '''
|
|
|
|
require './test/syntax-error'
|
|
|
|
''',
|
|
|
|
"""
|
|
|
|
#{path.join __dirname, 'syntax-error.coffee'}:1:15: error: unexpected in
|
|
|
|
foo in bar or in baz
|
|
|
|
^^
|
|
|
|
"""
|
|
|
|
finally
|
2016-10-19 00:49:15 -04:00
|
|
|
fs.unlinkSync 'test/syntax-error.coffee'
|
2014-01-21 21:44:50 -05:00
|
|
|
|
2014-02-07 07:01:01 -05:00
|
|
|
|
2014-01-21 21:44:50 -05:00
|
|
|
test "#1096: unexpected generated tokens", ->
|
|
|
|
# Implicit ends
|
|
|
|
assertErrorFormat 'a:, b', '''
|
|
|
|
[stdin]:1:3: error: unexpected ,
|
|
|
|
a:, b
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
# Explicit ends
|
|
|
|
assertErrorFormat '(a:)', '''
|
|
|
|
[stdin]:1:4: error: unexpected )
|
|
|
|
(a:)
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
# Unexpected end of file
|
|
|
|
assertErrorFormat 'a:', '''
|
|
|
|
[stdin]:1:3: error: unexpected end of input
|
|
|
|
a:
|
|
|
|
^
|
|
|
|
'''
|
2015-01-12 14:40:59 -05:00
|
|
|
assertErrorFormat 'a +', '''
|
|
|
|
[stdin]:1:4: error: unexpected end of input
|
|
|
|
a +
|
|
|
|
^
|
|
|
|
'''
|
Fix #3597: Allow interpolations in object keys
The following is now allowed:
o =
a: 1
b: 2
"#{'c'}": 3
"#{'d'}": 4
e: 5
"#{'f'}": 6
g: 7
It compiles to:
o = (
obj = {
a: 1,
b: 2
},
obj["" + 'c'] = 3,
obj["" + 'd'] = 4,
obj.e = 5,
obj["" + 'f'] = 6,
obj.g = 7,
obj
);
- Closes #3039. Empty interpolations in object keys are now _supposed_ to be
allowed.
- Closes #1131. No need to improve error messages for attempted key
interpolation anymore.
- Implementing this required fixing the following bug: `("" + a): 1` used to
error out on the colon, saying "unexpected colon". But really, it is the
attempted object key that is unexpected. Now the error is on the opening
parenthesis instead.
- However, the above fix broke some error message tests for regexes. The easiest
way to fix this was to make a seemingly unrelated change: The error messages
for unexpected identifiers, numbers, strings and regexes now say for example
'unexpected string' instead of 'unexpected """some #{really long} string"""'.
In other words, the tag _name_ is used instead of the tag _value_.
This was way easier to implement, and is more helpful to the user. Using the
tag value is good for operators, reserved words and the like, but not for
tokens which can contain any text. For example, 'unexpected identifier' is
better than 'unexpected expected' (if a variable called 'expected' was used
erraneously).
- While writing tests for the above point I found a few minor bugs with string
locations which have been fixed.
2015-02-07 14:16:59 -05:00
|
|
|
# Unexpected key in implicit object (an implicit object itself is _not_
|
|
|
|
# unexpected here)
|
2014-01-21 21:44:50 -05:00
|
|
|
assertErrorFormat '''
|
|
|
|
for i in [1]:
|
|
|
|
1
|
|
|
|
''', '''
|
Fix #3597: Allow interpolations in object keys
The following is now allowed:
o =
a: 1
b: 2
"#{'c'}": 3
"#{'d'}": 4
e: 5
"#{'f'}": 6
g: 7
It compiles to:
o = (
obj = {
a: 1,
b: 2
},
obj["" + 'c'] = 3,
obj["" + 'd'] = 4,
obj.e = 5,
obj["" + 'f'] = 6,
obj.g = 7,
obj
);
- Closes #3039. Empty interpolations in object keys are now _supposed_ to be
allowed.
- Closes #1131. No need to improve error messages for attempted key
interpolation anymore.
- Implementing this required fixing the following bug: `("" + a): 1` used to
error out on the colon, saying "unexpected colon". But really, it is the
attempted object key that is unexpected. Now the error is on the opening
parenthesis instead.
- However, the above fix broke some error message tests for regexes. The easiest
way to fix this was to make a seemingly unrelated change: The error messages
for unexpected identifiers, numbers, strings and regexes now say for example
'unexpected string' instead of 'unexpected """some #{really long} string"""'.
In other words, the tag _name_ is used instead of the tag _value_.
This was way easier to implement, and is more helpful to the user. Using the
tag value is good for operators, reserved words and the like, but not for
tokens which can contain any text. For example, 'unexpected identifier' is
better than 'unexpected expected' (if a variable called 'expected' was used
erraneously).
- While writing tests for the above point I found a few minor bugs with string
locations which have been fixed.
2015-02-07 14:16:59 -05:00
|
|
|
[stdin]:1:10: error: unexpected [
|
2014-01-21 21:44:50 -05:00
|
|
|
for i in [1]:
|
Fix #3597: Allow interpolations in object keys
The following is now allowed:
o =
a: 1
b: 2
"#{'c'}": 3
"#{'d'}": 4
e: 5
"#{'f'}": 6
g: 7
It compiles to:
o = (
obj = {
a: 1,
b: 2
},
obj["" + 'c'] = 3,
obj["" + 'd'] = 4,
obj.e = 5,
obj["" + 'f'] = 6,
obj.g = 7,
obj
);
- Closes #3039. Empty interpolations in object keys are now _supposed_ to be
allowed.
- Closes #1131. No need to improve error messages for attempted key
interpolation anymore.
- Implementing this required fixing the following bug: `("" + a): 1` used to
error out on the colon, saying "unexpected colon". But really, it is the
attempted object key that is unexpected. Now the error is on the opening
parenthesis instead.
- However, the above fix broke some error message tests for regexes. The easiest
way to fix this was to make a seemingly unrelated change: The error messages
for unexpected identifiers, numbers, strings and regexes now say for example
'unexpected string' instead of 'unexpected """some #{really long} string"""'.
In other words, the tag _name_ is used instead of the tag _value_.
This was way easier to implement, and is more helpful to the user. Using the
tag value is good for operators, reserved words and the like, but not for
tokens which can contain any text. For example, 'unexpected identifier' is
better than 'unexpected expected' (if a variable called 'expected' was used
erraneously).
- While writing tests for the above point I found a few minor bugs with string
locations which have been fixed.
2015-02-07 14:16:59 -05:00
|
|
|
^
|
2014-01-21 21:44:50 -05:00
|
|
|
'''
|
2015-02-03 14:42:50 -05:00
|
|
|
# Unexpected regex
|
|
|
|
assertErrorFormat '{/a/i: val}', '''
|
Fix #3597: Allow interpolations in object keys
The following is now allowed:
o =
a: 1
b: 2
"#{'c'}": 3
"#{'d'}": 4
e: 5
"#{'f'}": 6
g: 7
It compiles to:
o = (
obj = {
a: 1,
b: 2
},
obj["" + 'c'] = 3,
obj["" + 'd'] = 4,
obj.e = 5,
obj["" + 'f'] = 6,
obj.g = 7,
obj
);
- Closes #3039. Empty interpolations in object keys are now _supposed_ to be
allowed.
- Closes #1131. No need to improve error messages for attempted key
interpolation anymore.
- Implementing this required fixing the following bug: `("" + a): 1` used to
error out on the colon, saying "unexpected colon". But really, it is the
attempted object key that is unexpected. Now the error is on the opening
parenthesis instead.
- However, the above fix broke some error message tests for regexes. The easiest
way to fix this was to make a seemingly unrelated change: The error messages
for unexpected identifiers, numbers, strings and regexes now say for example
'unexpected string' instead of 'unexpected """some #{really long} string"""'.
In other words, the tag _name_ is used instead of the tag _value_.
This was way easier to implement, and is more helpful to the user. Using the
tag value is good for operators, reserved words and the like, but not for
tokens which can contain any text. For example, 'unexpected identifier' is
better than 'unexpected expected' (if a variable called 'expected' was used
erraneously).
- While writing tests for the above point I found a few minor bugs with string
locations which have been fixed.
2015-02-07 14:16:59 -05:00
|
|
|
[stdin]:1:2: error: unexpected regex
|
2015-02-03 14:42:50 -05:00
|
|
|
{/a/i: val}
|
|
|
|
^^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '{///a///i: val}', '''
|
Fix #3597: Allow interpolations in object keys
The following is now allowed:
o =
a: 1
b: 2
"#{'c'}": 3
"#{'d'}": 4
e: 5
"#{'f'}": 6
g: 7
It compiles to:
o = (
obj = {
a: 1,
b: 2
},
obj["" + 'c'] = 3,
obj["" + 'd'] = 4,
obj.e = 5,
obj["" + 'f'] = 6,
obj.g = 7,
obj
);
- Closes #3039. Empty interpolations in object keys are now _supposed_ to be
allowed.
- Closes #1131. No need to improve error messages for attempted key
interpolation anymore.
- Implementing this required fixing the following bug: `("" + a): 1` used to
error out on the colon, saying "unexpected colon". But really, it is the
attempted object key that is unexpected. Now the error is on the opening
parenthesis instead.
- However, the above fix broke some error message tests for regexes. The easiest
way to fix this was to make a seemingly unrelated change: The error messages
for unexpected identifiers, numbers, strings and regexes now say for example
'unexpected string' instead of 'unexpected """some #{really long} string"""'.
In other words, the tag _name_ is used instead of the tag _value_.
This was way easier to implement, and is more helpful to the user. Using the
tag value is good for operators, reserved words and the like, but not for
tokens which can contain any text. For example, 'unexpected identifier' is
better than 'unexpected expected' (if a variable called 'expected' was used
erraneously).
- While writing tests for the above point I found a few minor bugs with string
locations which have been fixed.
2015-02-07 14:16:59 -05:00
|
|
|
[stdin]:1:2: error: unexpected regex
|
2015-02-03 14:42:50 -05:00
|
|
|
{///a///i: val}
|
|
|
|
^^^^^^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '{///#{a}///i: val}', '''
|
Fix #3597: Allow interpolations in object keys
The following is now allowed:
o =
a: 1
b: 2
"#{'c'}": 3
"#{'d'}": 4
e: 5
"#{'f'}": 6
g: 7
It compiles to:
o = (
obj = {
a: 1,
b: 2
},
obj["" + 'c'] = 3,
obj["" + 'd'] = 4,
obj.e = 5,
obj["" + 'f'] = 6,
obj.g = 7,
obj
);
- Closes #3039. Empty interpolations in object keys are now _supposed_ to be
allowed.
- Closes #1131. No need to improve error messages for attempted key
interpolation anymore.
- Implementing this required fixing the following bug: `("" + a): 1` used to
error out on the colon, saying "unexpected colon". But really, it is the
attempted object key that is unexpected. Now the error is on the opening
parenthesis instead.
- However, the above fix broke some error message tests for regexes. The easiest
way to fix this was to make a seemingly unrelated change: The error messages
for unexpected identifiers, numbers, strings and regexes now say for example
'unexpected string' instead of 'unexpected """some #{really long} string"""'.
In other words, the tag _name_ is used instead of the tag _value_.
This was way easier to implement, and is more helpful to the user. Using the
tag value is good for operators, reserved words and the like, but not for
tokens which can contain any text. For example, 'unexpected identifier' is
better than 'unexpected expected' (if a variable called 'expected' was used
erraneously).
- While writing tests for the above point I found a few minor bugs with string
locations which have been fixed.
2015-02-07 14:16:59 -05:00
|
|
|
[stdin]:1:2: error: unexpected regex
|
2015-02-03 14:42:50 -05:00
|
|
|
{///#{a}///i: val}
|
|
|
|
^^^^^^^^^^^
|
|
|
|
'''
|
Fix #3597: Allow interpolations in object keys
The following is now allowed:
o =
a: 1
b: 2
"#{'c'}": 3
"#{'d'}": 4
e: 5
"#{'f'}": 6
g: 7
It compiles to:
o = (
obj = {
a: 1,
b: 2
},
obj["" + 'c'] = 3,
obj["" + 'd'] = 4,
obj.e = 5,
obj["" + 'f'] = 6,
obj.g = 7,
obj
);
- Closes #3039. Empty interpolations in object keys are now _supposed_ to be
allowed.
- Closes #1131. No need to improve error messages for attempted key
interpolation anymore.
- Implementing this required fixing the following bug: `("" + a): 1` used to
error out on the colon, saying "unexpected colon". But really, it is the
attempted object key that is unexpected. Now the error is on the opening
parenthesis instead.
- However, the above fix broke some error message tests for regexes. The easiest
way to fix this was to make a seemingly unrelated change: The error messages
for unexpected identifiers, numbers, strings and regexes now say for example
'unexpected string' instead of 'unexpected """some #{really long} string"""'.
In other words, the tag _name_ is used instead of the tag _value_.
This was way easier to implement, and is more helpful to the user. Using the
tag value is good for operators, reserved words and the like, but not for
tokens which can contain any text. For example, 'unexpected identifier' is
better than 'unexpected expected' (if a variable called 'expected' was used
erraneously).
- While writing tests for the above point I found a few minor bugs with string
locations which have been fixed.
2015-02-07 14:16:59 -05:00
|
|
|
# Unexpected string
|
|
|
|
assertErrorFormat "a''", '''
|
|
|
|
[stdin]:1:2: error: unexpected string
|
|
|
|
a''
|
|
|
|
^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat 'a""', '''
|
|
|
|
[stdin]:1:2: error: unexpected string
|
|
|
|
a""
|
|
|
|
^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat "a'b'", '''
|
|
|
|
[stdin]:1:2: error: unexpected string
|
|
|
|
a'b'
|
|
|
|
^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat 'a"b"', '''
|
|
|
|
[stdin]:1:2: error: unexpected string
|
|
|
|
a"b"
|
|
|
|
^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat "a'''b'''", """
|
|
|
|
[stdin]:1:2: error: unexpected string
|
|
|
|
a'''b'''
|
|
|
|
^^^^^^^
|
|
|
|
"""
|
|
|
|
assertErrorFormat 'a"""b"""', '''
|
|
|
|
[stdin]:1:2: error: unexpected string
|
|
|
|
a"""b"""
|
|
|
|
^^^^^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat 'a"#{b}"', '''
|
|
|
|
[stdin]:1:2: error: unexpected string
|
|
|
|
a"#{b}"
|
|
|
|
^^^^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat 'a"""#{b}"""', '''
|
|
|
|
[stdin]:1:2: error: unexpected string
|
|
|
|
a"""#{b}"""
|
|
|
|
^^^^^^^^^^
|
|
|
|
'''
|
Support import and export of ES2015 modules (#4300)
This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages:
```js
import "module-name"
import defaultMember from "module-name"
import * as name from "module-name"
import { } from "module-name"
import { member } from "module-name"
import { member as alias } from "module-name"
import { member1, member2 as alias2, … } from "module-name"
import defaultMember, * as name from "module-name"
import defaultMember, { … } from "module-name"
export default expression
export class name
export { }
export { name }
export { name as exportedName }
export { name as default }
export { name1, name2 as exportedName2, name3 as default, … }
export * from "module-name"
export { … } from "module-name"
```
As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports:
```js
export name = …
```
CoffeeScript also supports optional commas within `{ … }`.
This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this.
This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used.
There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests:
* I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu)
* I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos)
The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 14:46:05 -04:00
|
|
|
assertErrorFormat 'import foo from "lib-#{version}"', '''
|
|
|
|
[stdin]:1:17: error: the name of the module to be imported from must be an uninterpolated string
|
|
|
|
import foo from "lib-#{version}"
|
|
|
|
^^^^^^^^^^^^^^^^
|
|
|
|
'''
|
|
|
|
|
Fix #3597: Allow interpolations in object keys
The following is now allowed:
o =
a: 1
b: 2
"#{'c'}": 3
"#{'d'}": 4
e: 5
"#{'f'}": 6
g: 7
It compiles to:
o = (
obj = {
a: 1,
b: 2
},
obj["" + 'c'] = 3,
obj["" + 'd'] = 4,
obj.e = 5,
obj["" + 'f'] = 6,
obj.g = 7,
obj
);
- Closes #3039. Empty interpolations in object keys are now _supposed_ to be
allowed.
- Closes #1131. No need to improve error messages for attempted key
interpolation anymore.
- Implementing this required fixing the following bug: `("" + a): 1` used to
error out on the colon, saying "unexpected colon". But really, it is the
attempted object key that is unexpected. Now the error is on the opening
parenthesis instead.
- However, the above fix broke some error message tests for regexes. The easiest
way to fix this was to make a seemingly unrelated change: The error messages
for unexpected identifiers, numbers, strings and regexes now say for example
'unexpected string' instead of 'unexpected """some #{really long} string"""'.
In other words, the tag _name_ is used instead of the tag _value_.
This was way easier to implement, and is more helpful to the user. Using the
tag value is good for operators, reserved words and the like, but not for
tokens which can contain any text. For example, 'unexpected identifier' is
better than 'unexpected expected' (if a variable called 'expected' was used
erraneously).
- While writing tests for the above point I found a few minor bugs with string
locations which have been fixed.
2015-02-07 14:16:59 -05:00
|
|
|
# Unexpected number
|
|
|
|
assertErrorFormat '"a"0x00Af2', '''
|
|
|
|
[stdin]:1:4: error: unexpected number
|
|
|
|
"a"0x00Af2
|
|
|
|
^^^^^^^
|
|
|
|
'''
|
2014-01-26 00:25:13 -05:00
|
|
|
|
2015-01-12 14:10:54 -05:00
|
|
|
test "#1316: unexpected end of interpolation", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
"#{+}"
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:5: error: unexpected end of interpolation
|
|
|
|
"#{+}"
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
"#{++}"
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:6: error: unexpected end of interpolation
|
|
|
|
"#{++}"
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
"#{-}"
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:5: error: unexpected end of interpolation
|
|
|
|
"#{-}"
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
"#{--}"
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:6: error: unexpected end of interpolation
|
|
|
|
"#{--}"
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
"#{~}"
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:5: error: unexpected end of interpolation
|
|
|
|
"#{~}"
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
"#{!}"
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:5: error: unexpected end of interpolation
|
|
|
|
"#{!}"
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
"#{not}"
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:7: error: unexpected end of interpolation
|
|
|
|
"#{not}"
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
"#{5) + (4}_"
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:5: error: unmatched )
|
|
|
|
"#{5) + (4}_"
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
# #2918
|
|
|
|
assertErrorFormat '''
|
|
|
|
"#{foo.}"
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:8: error: unexpected end of interpolation
|
|
|
|
"#{foo.}"
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
|
2014-01-26 00:25:13 -05:00
|
|
|
test "#3325: implicit indentation errors", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
i for i in a then i
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:14: error: unexpected then
|
|
|
|
i for i in a then i
|
|
|
|
^^^^
|
|
|
|
'''
|
|
|
|
|
|
|
|
test "explicit indentation errors", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
a = b
|
|
|
|
c
|
|
|
|
''', '''
|
|
|
|
[stdin]:2:1: error: unexpected indentation
|
|
|
|
c
|
|
|
|
^^
|
|
|
|
'''
|
Refactor interpolation (and string and regex) handling in lexer
- Fix #3394: Unclosed single-quoted strings (both regular ones and heredocs)
used to pass through the lexer, causing a parsing error later, while
double-quoted strings caused an error already in the lexing phase. Now both
single and double-quoted unclosed strings error out in the lexer (which is the
more logical option) with consistent error messages. This also fixes the last
comment by @satyr in #3301.
- Similar to the above, unclosed heregexes also used to pass through the lexer
and not error until in the parsing phase, which resulted in confusing error
messages. This has been fixed, too.
- Fix #3348, by adding passing tests.
- Fix #3529: If a string starts with an interpolation, an empty string is no
longer emitted before the interpolation (unless it is needed to coerce the
interpolation into a string).
- Block comments cannot contain `*/`. Now the error message also shows exactly
where the offending `*/`. This improvement might seem unrelated, but I had to
touch that code anyway to refactor string and regex related code, and the
change was very trivial. Moreover, it's consistent with the next two points.
- Regexes cannot start with `*`. Now the error message also shows exactly where
the offending `*` is. (It might actually not be exatly at the start in
heregexes.) It is a very minor improvement, but it was trivial to add.
- Octal escapes in strings are forbidden in CoffeeScript (just like in
JavaScript strict mode). However, this used to be the case only for regular
strings. Now they are also forbidden in heredocs. Moreover, the errors now
point at the offending octal escape.
- Invalid regex flags are no longer allowed. This includes repeated modifiers
and unknown ones. Moreover, invalid modifiers do not stop a heregex from
being matched, which results in better error messages.
- Fix #3621: `///a#{1}///` compiles to `RegExp("a" + 1)`. So does
`RegExp("a#{1}")`. Still, those two code snippets used to generate different
tokens, which is a bit weird, but more importantly causes problems for
coffeelint (see clutchski/coffeelint#340). This required lots of tests in
test/location.coffee to be updated. Note that some updates to those tests are
unrelated to this point; some have been updated to be more consistent (I
discovered this because the refactored code happened to be seemingly more
correct).
- Regular regex literals used to erraneously allow newlines to be escaped,
causing invalid JavaScript output. This has been fixed.
- Heregexes may now be completely empty (`//////`), instead of erroring out with
a confusing message.
- Fix #2388: Heredocs and heregexes used to be lexed simply, which meant that
you couldn't nest a heredoc within a heredoc (double-quoted, that is) or a
heregex inside a heregex.
- Fix #2321: If you used division inside interpolation and then a slash later in
the string containing that interpolation, the division slash and the latter
slash was erraneously matched as a regex. This has been fixed.
- Indentation inside interpolations in heredocs no longer affect how much
indentation is removed from each line of the heredoc (which is more
intuitive).
- Whitespace is now correctly trimmed from the start and end of strings in a few
edge cases.
- Last but not least, the lexing of interpolated strings now seems to be more
efficient. For a regular double-quoted string, we used to use a custom
function to find the end of it (taking interpolations and interpolations
within interpolations etc. into account). Then we used to re-find the
interpolations and recursively lex their contents. In effect, the same string
was processed twice, or even more in the case of deeper nesting of
interpolations. Now the same string is processed just once.
- Code duplication between regular strings, heredocs, regular regexes and
heregexes has been reduced.
- The above two points should result in more easily read code, too.
2015-01-03 17:40:43 -05:00
|
|
|
|
|
|
|
test "unclosed strings", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
'
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:1: error: missing '
|
|
|
|
'
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
"
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:1: error: missing "
|
|
|
|
"
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat """
|
|
|
|
'''
|
|
|
|
""", """
|
|
|
|
[stdin]:1:1: error: missing '''
|
|
|
|
'''
|
2015-02-06 04:52:02 -05:00
|
|
|
^^^
|
Refactor interpolation (and string and regex) handling in lexer
- Fix #3394: Unclosed single-quoted strings (both regular ones and heredocs)
used to pass through the lexer, causing a parsing error later, while
double-quoted strings caused an error already in the lexing phase. Now both
single and double-quoted unclosed strings error out in the lexer (which is the
more logical option) with consistent error messages. This also fixes the last
comment by @satyr in #3301.
- Similar to the above, unclosed heregexes also used to pass through the lexer
and not error until in the parsing phase, which resulted in confusing error
messages. This has been fixed, too.
- Fix #3348, by adding passing tests.
- Fix #3529: If a string starts with an interpolation, an empty string is no
longer emitted before the interpolation (unless it is needed to coerce the
interpolation into a string).
- Block comments cannot contain `*/`. Now the error message also shows exactly
where the offending `*/`. This improvement might seem unrelated, but I had to
touch that code anyway to refactor string and regex related code, and the
change was very trivial. Moreover, it's consistent with the next two points.
- Regexes cannot start with `*`. Now the error message also shows exactly where
the offending `*` is. (It might actually not be exatly at the start in
heregexes.) It is a very minor improvement, but it was trivial to add.
- Octal escapes in strings are forbidden in CoffeeScript (just like in
JavaScript strict mode). However, this used to be the case only for regular
strings. Now they are also forbidden in heredocs. Moreover, the errors now
point at the offending octal escape.
- Invalid regex flags are no longer allowed. This includes repeated modifiers
and unknown ones. Moreover, invalid modifiers do not stop a heregex from
being matched, which results in better error messages.
- Fix #3621: `///a#{1}///` compiles to `RegExp("a" + 1)`. So does
`RegExp("a#{1}")`. Still, those two code snippets used to generate different
tokens, which is a bit weird, but more importantly causes problems for
coffeelint (see clutchski/coffeelint#340). This required lots of tests in
test/location.coffee to be updated. Note that some updates to those tests are
unrelated to this point; some have been updated to be more consistent (I
discovered this because the refactored code happened to be seemingly more
correct).
- Regular regex literals used to erraneously allow newlines to be escaped,
causing invalid JavaScript output. This has been fixed.
- Heregexes may now be completely empty (`//////`), instead of erroring out with
a confusing message.
- Fix #2388: Heredocs and heregexes used to be lexed simply, which meant that
you couldn't nest a heredoc within a heredoc (double-quoted, that is) or a
heregex inside a heregex.
- Fix #2321: If you used division inside interpolation and then a slash later in
the string containing that interpolation, the division slash and the latter
slash was erraneously matched as a regex. This has been fixed.
- Indentation inside interpolations in heredocs no longer affect how much
indentation is removed from each line of the heredoc (which is more
intuitive).
- Whitespace is now correctly trimmed from the start and end of strings in a few
edge cases.
- Last but not least, the lexing of interpolated strings now seems to be more
efficient. For a regular double-quoted string, we used to use a custom
function to find the end of it (taking interpolations and interpolations
within interpolations etc. into account). Then we used to re-find the
interpolations and recursively lex their contents. In effect, the same string
was processed twice, or even more in the case of deeper nesting of
interpolations. Now the same string is processed just once.
- Code duplication between regular strings, heredocs, regular regexes and
heregexes has been reduced.
- The above two points should result in more easily read code, too.
2015-01-03 17:40:43 -05:00
|
|
|
"""
|
|
|
|
assertErrorFormat '''
|
|
|
|
"""
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:1: error: missing """
|
|
|
|
"""
|
2015-02-06 04:52:02 -05:00
|
|
|
^^^
|
Refactor interpolation (and string and regex) handling in lexer
- Fix #3394: Unclosed single-quoted strings (both regular ones and heredocs)
used to pass through the lexer, causing a parsing error later, while
double-quoted strings caused an error already in the lexing phase. Now both
single and double-quoted unclosed strings error out in the lexer (which is the
more logical option) with consistent error messages. This also fixes the last
comment by @satyr in #3301.
- Similar to the above, unclosed heregexes also used to pass through the lexer
and not error until in the parsing phase, which resulted in confusing error
messages. This has been fixed, too.
- Fix #3348, by adding passing tests.
- Fix #3529: If a string starts with an interpolation, an empty string is no
longer emitted before the interpolation (unless it is needed to coerce the
interpolation into a string).
- Block comments cannot contain `*/`. Now the error message also shows exactly
where the offending `*/`. This improvement might seem unrelated, but I had to
touch that code anyway to refactor string and regex related code, and the
change was very trivial. Moreover, it's consistent with the next two points.
- Regexes cannot start with `*`. Now the error message also shows exactly where
the offending `*` is. (It might actually not be exatly at the start in
heregexes.) It is a very minor improvement, but it was trivial to add.
- Octal escapes in strings are forbidden in CoffeeScript (just like in
JavaScript strict mode). However, this used to be the case only for regular
strings. Now they are also forbidden in heredocs. Moreover, the errors now
point at the offending octal escape.
- Invalid regex flags are no longer allowed. This includes repeated modifiers
and unknown ones. Moreover, invalid modifiers do not stop a heregex from
being matched, which results in better error messages.
- Fix #3621: `///a#{1}///` compiles to `RegExp("a" + 1)`. So does
`RegExp("a#{1}")`. Still, those two code snippets used to generate different
tokens, which is a bit weird, but more importantly causes problems for
coffeelint (see clutchski/coffeelint#340). This required lots of tests in
test/location.coffee to be updated. Note that some updates to those tests are
unrelated to this point; some have been updated to be more consistent (I
discovered this because the refactored code happened to be seemingly more
correct).
- Regular regex literals used to erraneously allow newlines to be escaped,
causing invalid JavaScript output. This has been fixed.
- Heregexes may now be completely empty (`//////`), instead of erroring out with
a confusing message.
- Fix #2388: Heredocs and heregexes used to be lexed simply, which meant that
you couldn't nest a heredoc within a heredoc (double-quoted, that is) or a
heregex inside a heregex.
- Fix #2321: If you used division inside interpolation and then a slash later in
the string containing that interpolation, the division slash and the latter
slash was erraneously matched as a regex. This has been fixed.
- Indentation inside interpolations in heredocs no longer affect how much
indentation is removed from each line of the heredoc (which is more
intuitive).
- Whitespace is now correctly trimmed from the start and end of strings in a few
edge cases.
- Last but not least, the lexing of interpolated strings now seems to be more
efficient. For a regular double-quoted string, we used to use a custom
function to find the end of it (taking interpolations and interpolations
within interpolations etc. into account). Then we used to re-find the
interpolations and recursively lex their contents. In effect, the same string
was processed twice, or even more in the case of deeper nesting of
interpolations. Now the same string is processed just once.
- Code duplication between regular strings, heredocs, regular regexes and
heregexes has been reduced.
- The above two points should result in more easily read code, too.
2015-01-03 17:40:43 -05:00
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
"#{"
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:4: error: missing "
|
|
|
|
"#{"
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
"""#{"
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:6: error: missing "
|
|
|
|
"""#{"
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
"#{"""
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:4: error: missing """
|
|
|
|
"#{"""
|
2015-02-06 04:52:02 -05:00
|
|
|
^^^
|
Refactor interpolation (and string and regex) handling in lexer
- Fix #3394: Unclosed single-quoted strings (both regular ones and heredocs)
used to pass through the lexer, causing a parsing error later, while
double-quoted strings caused an error already in the lexing phase. Now both
single and double-quoted unclosed strings error out in the lexer (which is the
more logical option) with consistent error messages. This also fixes the last
comment by @satyr in #3301.
- Similar to the above, unclosed heregexes also used to pass through the lexer
and not error until in the parsing phase, which resulted in confusing error
messages. This has been fixed, too.
- Fix #3348, by adding passing tests.
- Fix #3529: If a string starts with an interpolation, an empty string is no
longer emitted before the interpolation (unless it is needed to coerce the
interpolation into a string).
- Block comments cannot contain `*/`. Now the error message also shows exactly
where the offending `*/`. This improvement might seem unrelated, but I had to
touch that code anyway to refactor string and regex related code, and the
change was very trivial. Moreover, it's consistent with the next two points.
- Regexes cannot start with `*`. Now the error message also shows exactly where
the offending `*` is. (It might actually not be exatly at the start in
heregexes.) It is a very minor improvement, but it was trivial to add.
- Octal escapes in strings are forbidden in CoffeeScript (just like in
JavaScript strict mode). However, this used to be the case only for regular
strings. Now they are also forbidden in heredocs. Moreover, the errors now
point at the offending octal escape.
- Invalid regex flags are no longer allowed. This includes repeated modifiers
and unknown ones. Moreover, invalid modifiers do not stop a heregex from
being matched, which results in better error messages.
- Fix #3621: `///a#{1}///` compiles to `RegExp("a" + 1)`. So does
`RegExp("a#{1}")`. Still, those two code snippets used to generate different
tokens, which is a bit weird, but more importantly causes problems for
coffeelint (see clutchski/coffeelint#340). This required lots of tests in
test/location.coffee to be updated. Note that some updates to those tests are
unrelated to this point; some have been updated to be more consistent (I
discovered this because the refactored code happened to be seemingly more
correct).
- Regular regex literals used to erraneously allow newlines to be escaped,
causing invalid JavaScript output. This has been fixed.
- Heregexes may now be completely empty (`//////`), instead of erroring out with
a confusing message.
- Fix #2388: Heredocs and heregexes used to be lexed simply, which meant that
you couldn't nest a heredoc within a heredoc (double-quoted, that is) or a
heregex inside a heregex.
- Fix #2321: If you used division inside interpolation and then a slash later in
the string containing that interpolation, the division slash and the latter
slash was erraneously matched as a regex. This has been fixed.
- Indentation inside interpolations in heredocs no longer affect how much
indentation is removed from each line of the heredoc (which is more
intuitive).
- Whitespace is now correctly trimmed from the start and end of strings in a few
edge cases.
- Last but not least, the lexing of interpolated strings now seems to be more
efficient. For a regular double-quoted string, we used to use a custom
function to find the end of it (taking interpolations and interpolations
within interpolations etc. into account). Then we used to re-find the
interpolations and recursively lex their contents. In effect, the same string
was processed twice, or even more in the case of deeper nesting of
interpolations. Now the same string is processed just once.
- Code duplication between regular strings, heredocs, regular regexes and
heregexes has been reduced.
- The above two points should result in more easily read code, too.
2015-01-03 17:40:43 -05:00
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
"""#{"""
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:6: error: missing """
|
|
|
|
"""#{"""
|
2015-02-06 04:52:02 -05:00
|
|
|
^^^
|
Refactor interpolation (and string and regex) handling in lexer
- Fix #3394: Unclosed single-quoted strings (both regular ones and heredocs)
used to pass through the lexer, causing a parsing error later, while
double-quoted strings caused an error already in the lexing phase. Now both
single and double-quoted unclosed strings error out in the lexer (which is the
more logical option) with consistent error messages. This also fixes the last
comment by @satyr in #3301.
- Similar to the above, unclosed heregexes also used to pass through the lexer
and not error until in the parsing phase, which resulted in confusing error
messages. This has been fixed, too.
- Fix #3348, by adding passing tests.
- Fix #3529: If a string starts with an interpolation, an empty string is no
longer emitted before the interpolation (unless it is needed to coerce the
interpolation into a string).
- Block comments cannot contain `*/`. Now the error message also shows exactly
where the offending `*/`. This improvement might seem unrelated, but I had to
touch that code anyway to refactor string and regex related code, and the
change was very trivial. Moreover, it's consistent with the next two points.
- Regexes cannot start with `*`. Now the error message also shows exactly where
the offending `*` is. (It might actually not be exatly at the start in
heregexes.) It is a very minor improvement, but it was trivial to add.
- Octal escapes in strings are forbidden in CoffeeScript (just like in
JavaScript strict mode). However, this used to be the case only for regular
strings. Now they are also forbidden in heredocs. Moreover, the errors now
point at the offending octal escape.
- Invalid regex flags are no longer allowed. This includes repeated modifiers
and unknown ones. Moreover, invalid modifiers do not stop a heregex from
being matched, which results in better error messages.
- Fix #3621: `///a#{1}///` compiles to `RegExp("a" + 1)`. So does
`RegExp("a#{1}")`. Still, those two code snippets used to generate different
tokens, which is a bit weird, but more importantly causes problems for
coffeelint (see clutchski/coffeelint#340). This required lots of tests in
test/location.coffee to be updated. Note that some updates to those tests are
unrelated to this point; some have been updated to be more consistent (I
discovered this because the refactored code happened to be seemingly more
correct).
- Regular regex literals used to erraneously allow newlines to be escaped,
causing invalid JavaScript output. This has been fixed.
- Heregexes may now be completely empty (`//////`), instead of erroring out with
a confusing message.
- Fix #2388: Heredocs and heregexes used to be lexed simply, which meant that
you couldn't nest a heredoc within a heredoc (double-quoted, that is) or a
heregex inside a heregex.
- Fix #2321: If you used division inside interpolation and then a slash later in
the string containing that interpolation, the division slash and the latter
slash was erraneously matched as a regex. This has been fixed.
- Indentation inside interpolations in heredocs no longer affect how much
indentation is removed from each line of the heredoc (which is more
intuitive).
- Whitespace is now correctly trimmed from the start and end of strings in a few
edge cases.
- Last but not least, the lexing of interpolated strings now seems to be more
efficient. For a regular double-quoted string, we used to use a custom
function to find the end of it (taking interpolations and interpolations
within interpolations etc. into account). Then we used to re-find the
interpolations and recursively lex their contents. In effect, the same string
was processed twice, or even more in the case of deeper nesting of
interpolations. Now the same string is processed just once.
- Code duplication between regular strings, heredocs, regular regexes and
heregexes has been reduced.
- The above two points should result in more easily read code, too.
2015-01-03 17:40:43 -05:00
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
///#{"""
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:6: error: missing """
|
|
|
|
///#{"""
|
2015-02-06 04:52:02 -05:00
|
|
|
^^^
|
Refactor interpolation (and string and regex) handling in lexer
- Fix #3394: Unclosed single-quoted strings (both regular ones and heredocs)
used to pass through the lexer, causing a parsing error later, while
double-quoted strings caused an error already in the lexing phase. Now both
single and double-quoted unclosed strings error out in the lexer (which is the
more logical option) with consistent error messages. This also fixes the last
comment by @satyr in #3301.
- Similar to the above, unclosed heregexes also used to pass through the lexer
and not error until in the parsing phase, which resulted in confusing error
messages. This has been fixed, too.
- Fix #3348, by adding passing tests.
- Fix #3529: If a string starts with an interpolation, an empty string is no
longer emitted before the interpolation (unless it is needed to coerce the
interpolation into a string).
- Block comments cannot contain `*/`. Now the error message also shows exactly
where the offending `*/`. This improvement might seem unrelated, but I had to
touch that code anyway to refactor string and regex related code, and the
change was very trivial. Moreover, it's consistent with the next two points.
- Regexes cannot start with `*`. Now the error message also shows exactly where
the offending `*` is. (It might actually not be exatly at the start in
heregexes.) It is a very minor improvement, but it was trivial to add.
- Octal escapes in strings are forbidden in CoffeeScript (just like in
JavaScript strict mode). However, this used to be the case only for regular
strings. Now they are also forbidden in heredocs. Moreover, the errors now
point at the offending octal escape.
- Invalid regex flags are no longer allowed. This includes repeated modifiers
and unknown ones. Moreover, invalid modifiers do not stop a heregex from
being matched, which results in better error messages.
- Fix #3621: `///a#{1}///` compiles to `RegExp("a" + 1)`. So does
`RegExp("a#{1}")`. Still, those two code snippets used to generate different
tokens, which is a bit weird, but more importantly causes problems for
coffeelint (see clutchski/coffeelint#340). This required lots of tests in
test/location.coffee to be updated. Note that some updates to those tests are
unrelated to this point; some have been updated to be more consistent (I
discovered this because the refactored code happened to be seemingly more
correct).
- Regular regex literals used to erraneously allow newlines to be escaped,
causing invalid JavaScript output. This has been fixed.
- Heregexes may now be completely empty (`//////`), instead of erroring out with
a confusing message.
- Fix #2388: Heredocs and heregexes used to be lexed simply, which meant that
you couldn't nest a heredoc within a heredoc (double-quoted, that is) or a
heregex inside a heregex.
- Fix #2321: If you used division inside interpolation and then a slash later in
the string containing that interpolation, the division slash and the latter
slash was erraneously matched as a regex. This has been fixed.
- Indentation inside interpolations in heredocs no longer affect how much
indentation is removed from each line of the heredoc (which is more
intuitive).
- Whitespace is now correctly trimmed from the start and end of strings in a few
edge cases.
- Last but not least, the lexing of interpolated strings now seems to be more
efficient. For a regular double-quoted string, we used to use a custom
function to find the end of it (taking interpolations and interpolations
within interpolations etc. into account). Then we used to re-find the
interpolations and recursively lex their contents. In effect, the same string
was processed twice, or even more in the case of deeper nesting of
interpolations. Now the same string is processed just once.
- Code duplication between regular strings, heredocs, regular regexes and
heregexes has been reduced.
- The above two points should result in more easily read code, too.
2015-01-03 17:40:43 -05:00
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
"a
|
|
|
|
#{foo """
|
|
|
|
bar
|
|
|
|
#{ +'12 }
|
|
|
|
baz
|
|
|
|
"""} b"
|
|
|
|
''', '''
|
|
|
|
[stdin]:4:11: error: missing '
|
|
|
|
#{ +'12 }
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
# https://github.com/jashkenas/coffeescript/issues/3301#issuecomment-31735168
|
|
|
|
assertErrorFormat '''
|
|
|
|
# Note the double escaping; this would be `"""a\"""` real code.
|
|
|
|
"""a\\"""
|
|
|
|
''', '''
|
|
|
|
[stdin]:2:1: error: missing """
|
|
|
|
"""a\\"""
|
2015-02-06 04:52:02 -05:00
|
|
|
^^^
|
Refactor interpolation (and string and regex) handling in lexer
- Fix #3394: Unclosed single-quoted strings (both regular ones and heredocs)
used to pass through the lexer, causing a parsing error later, while
double-quoted strings caused an error already in the lexing phase. Now both
single and double-quoted unclosed strings error out in the lexer (which is the
more logical option) with consistent error messages. This also fixes the last
comment by @satyr in #3301.
- Similar to the above, unclosed heregexes also used to pass through the lexer
and not error until in the parsing phase, which resulted in confusing error
messages. This has been fixed, too.
- Fix #3348, by adding passing tests.
- Fix #3529: If a string starts with an interpolation, an empty string is no
longer emitted before the interpolation (unless it is needed to coerce the
interpolation into a string).
- Block comments cannot contain `*/`. Now the error message also shows exactly
where the offending `*/`. This improvement might seem unrelated, but I had to
touch that code anyway to refactor string and regex related code, and the
change was very trivial. Moreover, it's consistent with the next two points.
- Regexes cannot start with `*`. Now the error message also shows exactly where
the offending `*` is. (It might actually not be exatly at the start in
heregexes.) It is a very minor improvement, but it was trivial to add.
- Octal escapes in strings are forbidden in CoffeeScript (just like in
JavaScript strict mode). However, this used to be the case only for regular
strings. Now they are also forbidden in heredocs. Moreover, the errors now
point at the offending octal escape.
- Invalid regex flags are no longer allowed. This includes repeated modifiers
and unknown ones. Moreover, invalid modifiers do not stop a heregex from
being matched, which results in better error messages.
- Fix #3621: `///a#{1}///` compiles to `RegExp("a" + 1)`. So does
`RegExp("a#{1}")`. Still, those two code snippets used to generate different
tokens, which is a bit weird, but more importantly causes problems for
coffeelint (see clutchski/coffeelint#340). This required lots of tests in
test/location.coffee to be updated. Note that some updates to those tests are
unrelated to this point; some have been updated to be more consistent (I
discovered this because the refactored code happened to be seemingly more
correct).
- Regular regex literals used to erraneously allow newlines to be escaped,
causing invalid JavaScript output. This has been fixed.
- Heregexes may now be completely empty (`//////`), instead of erroring out with
a confusing message.
- Fix #2388: Heredocs and heregexes used to be lexed simply, which meant that
you couldn't nest a heredoc within a heredoc (double-quoted, that is) or a
heregex inside a heregex.
- Fix #2321: If you used division inside interpolation and then a slash later in
the string containing that interpolation, the division slash and the latter
slash was erraneously matched as a regex. This has been fixed.
- Indentation inside interpolations in heredocs no longer affect how much
indentation is removed from each line of the heredoc (which is more
intuitive).
- Whitespace is now correctly trimmed from the start and end of strings in a few
edge cases.
- Last but not least, the lexing of interpolated strings now seems to be more
efficient. For a regular double-quoted string, we used to use a custom
function to find the end of it (taking interpolations and interpolations
within interpolations etc. into account). Then we used to re-find the
interpolations and recursively lex their contents. In effect, the same string
was processed twice, or even more in the case of deeper nesting of
interpolations. Now the same string is processed just once.
- Code duplication between regular strings, heredocs, regular regexes and
heregexes has been reduced.
- The above two points should result in more easily read code, too.
2015-01-03 17:40:43 -05:00
|
|
|
'''
|
|
|
|
|
|
|
|
test "unclosed heregexes", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
///
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:1: error: missing ///
|
|
|
|
///
|
2015-02-06 04:52:02 -05:00
|
|
|
^^^
|
Refactor interpolation (and string and regex) handling in lexer
- Fix #3394: Unclosed single-quoted strings (both regular ones and heredocs)
used to pass through the lexer, causing a parsing error later, while
double-quoted strings caused an error already in the lexing phase. Now both
single and double-quoted unclosed strings error out in the lexer (which is the
more logical option) with consistent error messages. This also fixes the last
comment by @satyr in #3301.
- Similar to the above, unclosed heregexes also used to pass through the lexer
and not error until in the parsing phase, which resulted in confusing error
messages. This has been fixed, too.
- Fix #3348, by adding passing tests.
- Fix #3529: If a string starts with an interpolation, an empty string is no
longer emitted before the interpolation (unless it is needed to coerce the
interpolation into a string).
- Block comments cannot contain `*/`. Now the error message also shows exactly
where the offending `*/`. This improvement might seem unrelated, but I had to
touch that code anyway to refactor string and regex related code, and the
change was very trivial. Moreover, it's consistent with the next two points.
- Regexes cannot start with `*`. Now the error message also shows exactly where
the offending `*` is. (It might actually not be exatly at the start in
heregexes.) It is a very minor improvement, but it was trivial to add.
- Octal escapes in strings are forbidden in CoffeeScript (just like in
JavaScript strict mode). However, this used to be the case only for regular
strings. Now they are also forbidden in heredocs. Moreover, the errors now
point at the offending octal escape.
- Invalid regex flags are no longer allowed. This includes repeated modifiers
and unknown ones. Moreover, invalid modifiers do not stop a heregex from
being matched, which results in better error messages.
- Fix #3621: `///a#{1}///` compiles to `RegExp("a" + 1)`. So does
`RegExp("a#{1}")`. Still, those two code snippets used to generate different
tokens, which is a bit weird, but more importantly causes problems for
coffeelint (see clutchski/coffeelint#340). This required lots of tests in
test/location.coffee to be updated. Note that some updates to those tests are
unrelated to this point; some have been updated to be more consistent (I
discovered this because the refactored code happened to be seemingly more
correct).
- Regular regex literals used to erraneously allow newlines to be escaped,
causing invalid JavaScript output. This has been fixed.
- Heregexes may now be completely empty (`//////`), instead of erroring out with
a confusing message.
- Fix #2388: Heredocs and heregexes used to be lexed simply, which meant that
you couldn't nest a heredoc within a heredoc (double-quoted, that is) or a
heregex inside a heregex.
- Fix #2321: If you used division inside interpolation and then a slash later in
the string containing that interpolation, the division slash and the latter
slash was erraneously matched as a regex. This has been fixed.
- Indentation inside interpolations in heredocs no longer affect how much
indentation is removed from each line of the heredoc (which is more
intuitive).
- Whitespace is now correctly trimmed from the start and end of strings in a few
edge cases.
- Last but not least, the lexing of interpolated strings now seems to be more
efficient. For a regular double-quoted string, we used to use a custom
function to find the end of it (taking interpolations and interpolations
within interpolations etc. into account). Then we used to re-find the
interpolations and recursively lex their contents. In effect, the same string
was processed twice, or even more in the case of deeper nesting of
interpolations. Now the same string is processed just once.
- Code duplication between regular strings, heredocs, regular regexes and
heregexes has been reduced.
- The above two points should result in more easily read code, too.
2015-01-03 17:40:43 -05:00
|
|
|
'''
|
|
|
|
# https://github.com/jashkenas/coffeescript/issues/3301#issuecomment-31735168
|
|
|
|
assertErrorFormat '''
|
|
|
|
# Note the double escaping; this would be `///a\///` real code.
|
|
|
|
///a\\///
|
|
|
|
''', '''
|
|
|
|
[stdin]:2:1: error: missing ///
|
|
|
|
///a\\///
|
2015-02-06 04:52:02 -05:00
|
|
|
^^^
|
Refactor interpolation (and string and regex) handling in lexer
- Fix #3394: Unclosed single-quoted strings (both regular ones and heredocs)
used to pass through the lexer, causing a parsing error later, while
double-quoted strings caused an error already in the lexing phase. Now both
single and double-quoted unclosed strings error out in the lexer (which is the
more logical option) with consistent error messages. This also fixes the last
comment by @satyr in #3301.
- Similar to the above, unclosed heregexes also used to pass through the lexer
and not error until in the parsing phase, which resulted in confusing error
messages. This has been fixed, too.
- Fix #3348, by adding passing tests.
- Fix #3529: If a string starts with an interpolation, an empty string is no
longer emitted before the interpolation (unless it is needed to coerce the
interpolation into a string).
- Block comments cannot contain `*/`. Now the error message also shows exactly
where the offending `*/`. This improvement might seem unrelated, but I had to
touch that code anyway to refactor string and regex related code, and the
change was very trivial. Moreover, it's consistent with the next two points.
- Regexes cannot start with `*`. Now the error message also shows exactly where
the offending `*` is. (It might actually not be exatly at the start in
heregexes.) It is a very minor improvement, but it was trivial to add.
- Octal escapes in strings are forbidden in CoffeeScript (just like in
JavaScript strict mode). However, this used to be the case only for regular
strings. Now they are also forbidden in heredocs. Moreover, the errors now
point at the offending octal escape.
- Invalid regex flags are no longer allowed. This includes repeated modifiers
and unknown ones. Moreover, invalid modifiers do not stop a heregex from
being matched, which results in better error messages.
- Fix #3621: `///a#{1}///` compiles to `RegExp("a" + 1)`. So does
`RegExp("a#{1}")`. Still, those two code snippets used to generate different
tokens, which is a bit weird, but more importantly causes problems for
coffeelint (see clutchski/coffeelint#340). This required lots of tests in
test/location.coffee to be updated. Note that some updates to those tests are
unrelated to this point; some have been updated to be more consistent (I
discovered this because the refactored code happened to be seemingly more
correct).
- Regular regex literals used to erraneously allow newlines to be escaped,
causing invalid JavaScript output. This has been fixed.
- Heregexes may now be completely empty (`//////`), instead of erroring out with
a confusing message.
- Fix #2388: Heredocs and heregexes used to be lexed simply, which meant that
you couldn't nest a heredoc within a heredoc (double-quoted, that is) or a
heregex inside a heregex.
- Fix #2321: If you used division inside interpolation and then a slash later in
the string containing that interpolation, the division slash and the latter
slash was erraneously matched as a regex. This has been fixed.
- Indentation inside interpolations in heredocs no longer affect how much
indentation is removed from each line of the heredoc (which is more
intuitive).
- Whitespace is now correctly trimmed from the start and end of strings in a few
edge cases.
- Last but not least, the lexing of interpolated strings now seems to be more
efficient. For a regular double-quoted string, we used to use a custom
function to find the end of it (taking interpolations and interpolations
within interpolations etc. into account). Then we used to re-find the
interpolations and recursively lex their contents. In effect, the same string
was processed twice, or even more in the case of deeper nesting of
interpolations. Now the same string is processed just once.
- Code duplication between regular strings, heredocs, regular regexes and
heregexes has been reduced.
- The above two points should result in more easily read code, too.
2015-01-03 17:40:43 -05:00
|
|
|
'''
|
|
|
|
|
|
|
|
test "unexpected token after string", ->
|
|
|
|
# Parsing error.
|
|
|
|
assertErrorFormat '''
|
|
|
|
'foo'bar
|
|
|
|
''', '''
|
Fix #3597: Allow interpolations in object keys
The following is now allowed:
o =
a: 1
b: 2
"#{'c'}": 3
"#{'d'}": 4
e: 5
"#{'f'}": 6
g: 7
It compiles to:
o = (
obj = {
a: 1,
b: 2
},
obj["" + 'c'] = 3,
obj["" + 'd'] = 4,
obj.e = 5,
obj["" + 'f'] = 6,
obj.g = 7,
obj
);
- Closes #3039. Empty interpolations in object keys are now _supposed_ to be
allowed.
- Closes #1131. No need to improve error messages for attempted key
interpolation anymore.
- Implementing this required fixing the following bug: `("" + a): 1` used to
error out on the colon, saying "unexpected colon". But really, it is the
attempted object key that is unexpected. Now the error is on the opening
parenthesis instead.
- However, the above fix broke some error message tests for regexes. The easiest
way to fix this was to make a seemingly unrelated change: The error messages
for unexpected identifiers, numbers, strings and regexes now say for example
'unexpected string' instead of 'unexpected """some #{really long} string"""'.
In other words, the tag _name_ is used instead of the tag _value_.
This was way easier to implement, and is more helpful to the user. Using the
tag value is good for operators, reserved words and the like, but not for
tokens which can contain any text. For example, 'unexpected identifier' is
better than 'unexpected expected' (if a variable called 'expected' was used
erraneously).
- While writing tests for the above point I found a few minor bugs with string
locations which have been fixed.
2015-02-07 14:16:59 -05:00
|
|
|
[stdin]:1:6: error: unexpected identifier
|
Refactor interpolation (and string and regex) handling in lexer
- Fix #3394: Unclosed single-quoted strings (both regular ones and heredocs)
used to pass through the lexer, causing a parsing error later, while
double-quoted strings caused an error already in the lexing phase. Now both
single and double-quoted unclosed strings error out in the lexer (which is the
more logical option) with consistent error messages. This also fixes the last
comment by @satyr in #3301.
- Similar to the above, unclosed heregexes also used to pass through the lexer
and not error until in the parsing phase, which resulted in confusing error
messages. This has been fixed, too.
- Fix #3348, by adding passing tests.
- Fix #3529: If a string starts with an interpolation, an empty string is no
longer emitted before the interpolation (unless it is needed to coerce the
interpolation into a string).
- Block comments cannot contain `*/`. Now the error message also shows exactly
where the offending `*/`. This improvement might seem unrelated, but I had to
touch that code anyway to refactor string and regex related code, and the
change was very trivial. Moreover, it's consistent with the next two points.
- Regexes cannot start with `*`. Now the error message also shows exactly where
the offending `*` is. (It might actually not be exatly at the start in
heregexes.) It is a very minor improvement, but it was trivial to add.
- Octal escapes in strings are forbidden in CoffeeScript (just like in
JavaScript strict mode). However, this used to be the case only for regular
strings. Now they are also forbidden in heredocs. Moreover, the errors now
point at the offending octal escape.
- Invalid regex flags are no longer allowed. This includes repeated modifiers
and unknown ones. Moreover, invalid modifiers do not stop a heregex from
being matched, which results in better error messages.
- Fix #3621: `///a#{1}///` compiles to `RegExp("a" + 1)`. So does
`RegExp("a#{1}")`. Still, those two code snippets used to generate different
tokens, which is a bit weird, but more importantly causes problems for
coffeelint (see clutchski/coffeelint#340). This required lots of tests in
test/location.coffee to be updated. Note that some updates to those tests are
unrelated to this point; some have been updated to be more consistent (I
discovered this because the refactored code happened to be seemingly more
correct).
- Regular regex literals used to erraneously allow newlines to be escaped,
causing invalid JavaScript output. This has been fixed.
- Heregexes may now be completely empty (`//////`), instead of erroring out with
a confusing message.
- Fix #2388: Heredocs and heregexes used to be lexed simply, which meant that
you couldn't nest a heredoc within a heredoc (double-quoted, that is) or a
heregex inside a heregex.
- Fix #2321: If you used division inside interpolation and then a slash later in
the string containing that interpolation, the division slash and the latter
slash was erraneously matched as a regex. This has been fixed.
- Indentation inside interpolations in heredocs no longer affect how much
indentation is removed from each line of the heredoc (which is more
intuitive).
- Whitespace is now correctly trimmed from the start and end of strings in a few
edge cases.
- Last but not least, the lexing of interpolated strings now seems to be more
efficient. For a regular double-quoted string, we used to use a custom
function to find the end of it (taking interpolations and interpolations
within interpolations etc. into account). Then we used to re-find the
interpolations and recursively lex their contents. In effect, the same string
was processed twice, or even more in the case of deeper nesting of
interpolations. Now the same string is processed just once.
- Code duplication between regular strings, heredocs, regular regexes and
heregexes has been reduced.
- The above two points should result in more easily read code, too.
2015-01-03 17:40:43 -05:00
|
|
|
'foo'bar
|
|
|
|
^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
"foo"bar
|
|
|
|
''', '''
|
Fix #3597: Allow interpolations in object keys
The following is now allowed:
o =
a: 1
b: 2
"#{'c'}": 3
"#{'d'}": 4
e: 5
"#{'f'}": 6
g: 7
It compiles to:
o = (
obj = {
a: 1,
b: 2
},
obj["" + 'c'] = 3,
obj["" + 'd'] = 4,
obj.e = 5,
obj["" + 'f'] = 6,
obj.g = 7,
obj
);
- Closes #3039. Empty interpolations in object keys are now _supposed_ to be
allowed.
- Closes #1131. No need to improve error messages for attempted key
interpolation anymore.
- Implementing this required fixing the following bug: `("" + a): 1` used to
error out on the colon, saying "unexpected colon". But really, it is the
attempted object key that is unexpected. Now the error is on the opening
parenthesis instead.
- However, the above fix broke some error message tests for regexes. The easiest
way to fix this was to make a seemingly unrelated change: The error messages
for unexpected identifiers, numbers, strings and regexes now say for example
'unexpected string' instead of 'unexpected """some #{really long} string"""'.
In other words, the tag _name_ is used instead of the tag _value_.
This was way easier to implement, and is more helpful to the user. Using the
tag value is good for operators, reserved words and the like, but not for
tokens which can contain any text. For example, 'unexpected identifier' is
better than 'unexpected expected' (if a variable called 'expected' was used
erraneously).
- While writing tests for the above point I found a few minor bugs with string
locations which have been fixed.
2015-02-07 14:16:59 -05:00
|
|
|
[stdin]:1:6: error: unexpected identifier
|
Refactor interpolation (and string and regex) handling in lexer
- Fix #3394: Unclosed single-quoted strings (both regular ones and heredocs)
used to pass through the lexer, causing a parsing error later, while
double-quoted strings caused an error already in the lexing phase. Now both
single and double-quoted unclosed strings error out in the lexer (which is the
more logical option) with consistent error messages. This also fixes the last
comment by @satyr in #3301.
- Similar to the above, unclosed heregexes also used to pass through the lexer
and not error until in the parsing phase, which resulted in confusing error
messages. This has been fixed, too.
- Fix #3348, by adding passing tests.
- Fix #3529: If a string starts with an interpolation, an empty string is no
longer emitted before the interpolation (unless it is needed to coerce the
interpolation into a string).
- Block comments cannot contain `*/`. Now the error message also shows exactly
where the offending `*/`. This improvement might seem unrelated, but I had to
touch that code anyway to refactor string and regex related code, and the
change was very trivial. Moreover, it's consistent with the next two points.
- Regexes cannot start with `*`. Now the error message also shows exactly where
the offending `*` is. (It might actually not be exatly at the start in
heregexes.) It is a very minor improvement, but it was trivial to add.
- Octal escapes in strings are forbidden in CoffeeScript (just like in
JavaScript strict mode). However, this used to be the case only for regular
strings. Now they are also forbidden in heredocs. Moreover, the errors now
point at the offending octal escape.
- Invalid regex flags are no longer allowed. This includes repeated modifiers
and unknown ones. Moreover, invalid modifiers do not stop a heregex from
being matched, which results in better error messages.
- Fix #3621: `///a#{1}///` compiles to `RegExp("a" + 1)`. So does
`RegExp("a#{1}")`. Still, those two code snippets used to generate different
tokens, which is a bit weird, but more importantly causes problems for
coffeelint (see clutchski/coffeelint#340). This required lots of tests in
test/location.coffee to be updated. Note that some updates to those tests are
unrelated to this point; some have been updated to be more consistent (I
discovered this because the refactored code happened to be seemingly more
correct).
- Regular regex literals used to erraneously allow newlines to be escaped,
causing invalid JavaScript output. This has been fixed.
- Heregexes may now be completely empty (`//////`), instead of erroring out with
a confusing message.
- Fix #2388: Heredocs and heregexes used to be lexed simply, which meant that
you couldn't nest a heredoc within a heredoc (double-quoted, that is) or a
heregex inside a heregex.
- Fix #2321: If you used division inside interpolation and then a slash later in
the string containing that interpolation, the division slash and the latter
slash was erraneously matched as a regex. This has been fixed.
- Indentation inside interpolations in heredocs no longer affect how much
indentation is removed from each line of the heredoc (which is more
intuitive).
- Whitespace is now correctly trimmed from the start and end of strings in a few
edge cases.
- Last but not least, the lexing of interpolated strings now seems to be more
efficient. For a regular double-quoted string, we used to use a custom
function to find the end of it (taking interpolations and interpolations
within interpolations etc. into account). Then we used to re-find the
interpolations and recursively lex their contents. In effect, the same string
was processed twice, or even more in the case of deeper nesting of
interpolations. Now the same string is processed just once.
- Code duplication between regular strings, heredocs, regular regexes and
heregexes has been reduced.
- The above two points should result in more easily read code, too.
2015-01-03 17:40:43 -05:00
|
|
|
"foo"bar
|
|
|
|
^^^
|
|
|
|
'''
|
|
|
|
# Lexing error.
|
|
|
|
assertErrorFormat '''
|
|
|
|
'foo'bar'
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:9: error: missing '
|
|
|
|
'foo'bar'
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
"foo"bar"
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:9: error: missing "
|
|
|
|
"foo"bar"
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
|
|
|
|
test "#3348: Location data is wrong in interpolations with leading whitespace", ->
|
|
|
|
assertErrorFormat '''
|
Fix #3597: Allow interpolations in object keys
The following is now allowed:
o =
a: 1
b: 2
"#{'c'}": 3
"#{'d'}": 4
e: 5
"#{'f'}": 6
g: 7
It compiles to:
o = (
obj = {
a: 1,
b: 2
},
obj["" + 'c'] = 3,
obj["" + 'd'] = 4,
obj.e = 5,
obj["" + 'f'] = 6,
obj.g = 7,
obj
);
- Closes #3039. Empty interpolations in object keys are now _supposed_ to be
allowed.
- Closes #1131. No need to improve error messages for attempted key
interpolation anymore.
- Implementing this required fixing the following bug: `("" + a): 1` used to
error out on the colon, saying "unexpected colon". But really, it is the
attempted object key that is unexpected. Now the error is on the opening
parenthesis instead.
- However, the above fix broke some error message tests for regexes. The easiest
way to fix this was to make a seemingly unrelated change: The error messages
for unexpected identifiers, numbers, strings and regexes now say for example
'unexpected string' instead of 'unexpected """some #{really long} string"""'.
In other words, the tag _name_ is used instead of the tag _value_.
This was way easier to implement, and is more helpful to the user. Using the
tag value is good for operators, reserved words and the like, but not for
tokens which can contain any text. For example, 'unexpected identifier' is
better than 'unexpected expected' (if a variable called 'expected' was used
erraneously).
- While writing tests for the above point I found a few minor bugs with string
locations which have been fixed.
2015-02-07 14:16:59 -05:00
|
|
|
"#{ * }"
|
Refactor interpolation (and string and regex) handling in lexer
- Fix #3394: Unclosed single-quoted strings (both regular ones and heredocs)
used to pass through the lexer, causing a parsing error later, while
double-quoted strings caused an error already in the lexing phase. Now both
single and double-quoted unclosed strings error out in the lexer (which is the
more logical option) with consistent error messages. This also fixes the last
comment by @satyr in #3301.
- Similar to the above, unclosed heregexes also used to pass through the lexer
and not error until in the parsing phase, which resulted in confusing error
messages. This has been fixed, too.
- Fix #3348, by adding passing tests.
- Fix #3529: If a string starts with an interpolation, an empty string is no
longer emitted before the interpolation (unless it is needed to coerce the
interpolation into a string).
- Block comments cannot contain `*/`. Now the error message also shows exactly
where the offending `*/`. This improvement might seem unrelated, but I had to
touch that code anyway to refactor string and regex related code, and the
change was very trivial. Moreover, it's consistent with the next two points.
- Regexes cannot start with `*`. Now the error message also shows exactly where
the offending `*` is. (It might actually not be exatly at the start in
heregexes.) It is a very minor improvement, but it was trivial to add.
- Octal escapes in strings are forbidden in CoffeeScript (just like in
JavaScript strict mode). However, this used to be the case only for regular
strings. Now they are also forbidden in heredocs. Moreover, the errors now
point at the offending octal escape.
- Invalid regex flags are no longer allowed. This includes repeated modifiers
and unknown ones. Moreover, invalid modifiers do not stop a heregex from
being matched, which results in better error messages.
- Fix #3621: `///a#{1}///` compiles to `RegExp("a" + 1)`. So does
`RegExp("a#{1}")`. Still, those two code snippets used to generate different
tokens, which is a bit weird, but more importantly causes problems for
coffeelint (see clutchski/coffeelint#340). This required lots of tests in
test/location.coffee to be updated. Note that some updates to those tests are
unrelated to this point; some have been updated to be more consistent (I
discovered this because the refactored code happened to be seemingly more
correct).
- Regular regex literals used to erraneously allow newlines to be escaped,
causing invalid JavaScript output. This has been fixed.
- Heregexes may now be completely empty (`//////`), instead of erroring out with
a confusing message.
- Fix #2388: Heredocs and heregexes used to be lexed simply, which meant that
you couldn't nest a heredoc within a heredoc (double-quoted, that is) or a
heregex inside a heregex.
- Fix #2321: If you used division inside interpolation and then a slash later in
the string containing that interpolation, the division slash and the latter
slash was erraneously matched as a regex. This has been fixed.
- Indentation inside interpolations in heredocs no longer affect how much
indentation is removed from each line of the heredoc (which is more
intuitive).
- Whitespace is now correctly trimmed from the start and end of strings in a few
edge cases.
- Last but not least, the lexing of interpolated strings now seems to be more
efficient. For a regular double-quoted string, we used to use a custom
function to find the end of it (taking interpolations and interpolations
within interpolations etc. into account). Then we used to re-find the
interpolations and recursively lex their contents. In effect, the same string
was processed twice, or even more in the case of deeper nesting of
interpolations. Now the same string is processed just once.
- Code duplication between regular strings, heredocs, regular regexes and
heregexes has been reduced.
- The above two points should result in more easily read code, too.
2015-01-03 17:40:43 -05:00
|
|
|
''', '''
|
Fix #3597: Allow interpolations in object keys
The following is now allowed:
o =
a: 1
b: 2
"#{'c'}": 3
"#{'d'}": 4
e: 5
"#{'f'}": 6
g: 7
It compiles to:
o = (
obj = {
a: 1,
b: 2
},
obj["" + 'c'] = 3,
obj["" + 'd'] = 4,
obj.e = 5,
obj["" + 'f'] = 6,
obj.g = 7,
obj
);
- Closes #3039. Empty interpolations in object keys are now _supposed_ to be
allowed.
- Closes #1131. No need to improve error messages for attempted key
interpolation anymore.
- Implementing this required fixing the following bug: `("" + a): 1` used to
error out on the colon, saying "unexpected colon". But really, it is the
attempted object key that is unexpected. Now the error is on the opening
parenthesis instead.
- However, the above fix broke some error message tests for regexes. The easiest
way to fix this was to make a seemingly unrelated change: The error messages
for unexpected identifiers, numbers, strings and regexes now say for example
'unexpected string' instead of 'unexpected """some #{really long} string"""'.
In other words, the tag _name_ is used instead of the tag _value_.
This was way easier to implement, and is more helpful to the user. Using the
tag value is good for operators, reserved words and the like, but not for
tokens which can contain any text. For example, 'unexpected identifier' is
better than 'unexpected expected' (if a variable called 'expected' was used
erraneously).
- While writing tests for the above point I found a few minor bugs with string
locations which have been fixed.
2015-02-07 14:16:59 -05:00
|
|
|
[stdin]:1:5: error: unexpected *
|
|
|
|
"#{ * }"
|
|
|
|
^
|
Refactor interpolation (and string and regex) handling in lexer
- Fix #3394: Unclosed single-quoted strings (both regular ones and heredocs)
used to pass through the lexer, causing a parsing error later, while
double-quoted strings caused an error already in the lexing phase. Now both
single and double-quoted unclosed strings error out in the lexer (which is the
more logical option) with consistent error messages. This also fixes the last
comment by @satyr in #3301.
- Similar to the above, unclosed heregexes also used to pass through the lexer
and not error until in the parsing phase, which resulted in confusing error
messages. This has been fixed, too.
- Fix #3348, by adding passing tests.
- Fix #3529: If a string starts with an interpolation, an empty string is no
longer emitted before the interpolation (unless it is needed to coerce the
interpolation into a string).
- Block comments cannot contain `*/`. Now the error message also shows exactly
where the offending `*/`. This improvement might seem unrelated, but I had to
touch that code anyway to refactor string and regex related code, and the
change was very trivial. Moreover, it's consistent with the next two points.
- Regexes cannot start with `*`. Now the error message also shows exactly where
the offending `*` is. (It might actually not be exatly at the start in
heregexes.) It is a very minor improvement, but it was trivial to add.
- Octal escapes in strings are forbidden in CoffeeScript (just like in
JavaScript strict mode). However, this used to be the case only for regular
strings. Now they are also forbidden in heredocs. Moreover, the errors now
point at the offending octal escape.
- Invalid regex flags are no longer allowed. This includes repeated modifiers
and unknown ones. Moreover, invalid modifiers do not stop a heregex from
being matched, which results in better error messages.
- Fix #3621: `///a#{1}///` compiles to `RegExp("a" + 1)`. So does
`RegExp("a#{1}")`. Still, those two code snippets used to generate different
tokens, which is a bit weird, but more importantly causes problems for
coffeelint (see clutchski/coffeelint#340). This required lots of tests in
test/location.coffee to be updated. Note that some updates to those tests are
unrelated to this point; some have been updated to be more consistent (I
discovered this because the refactored code happened to be seemingly more
correct).
- Regular regex literals used to erraneously allow newlines to be escaped,
causing invalid JavaScript output. This has been fixed.
- Heregexes may now be completely empty (`//////`), instead of erroring out with
a confusing message.
- Fix #2388: Heredocs and heregexes used to be lexed simply, which meant that
you couldn't nest a heredoc within a heredoc (double-quoted, that is) or a
heregex inside a heregex.
- Fix #2321: If you used division inside interpolation and then a slash later in
the string containing that interpolation, the division slash and the latter
slash was erraneously matched as a regex. This has been fixed.
- Indentation inside interpolations in heredocs no longer affect how much
indentation is removed from each line of the heredoc (which is more
intuitive).
- Whitespace is now correctly trimmed from the start and end of strings in a few
edge cases.
- Last but not least, the lexing of interpolated strings now seems to be more
efficient. For a regular double-quoted string, we used to use a custom
function to find the end of it (taking interpolations and interpolations
within interpolations etc. into account). Then we used to re-find the
interpolations and recursively lex their contents. In effect, the same string
was processed twice, or even more in the case of deeper nesting of
interpolations. Now the same string is processed just once.
- Code duplication between regular strings, heredocs, regular regexes and
heregexes has been reduced.
- The above two points should result in more easily read code, too.
2015-01-03 17:40:43 -05:00
|
|
|
'''
|
|
|
|
|
|
|
|
test "octal escapes", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
"a\\0\\tb\\\\\\07c"
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:10: error: octal escape sequences are not allowed \\07
|
|
|
|
"a\\0\\tb\\\\\\07c"
|
2015-02-06 04:52:02 -05:00
|
|
|
\ \ \ \ ^\^^
|
Refactor interpolation (and string and regex) handling in lexer
- Fix #3394: Unclosed single-quoted strings (both regular ones and heredocs)
used to pass through the lexer, causing a parsing error later, while
double-quoted strings caused an error already in the lexing phase. Now both
single and double-quoted unclosed strings error out in the lexer (which is the
more logical option) with consistent error messages. This also fixes the last
comment by @satyr in #3301.
- Similar to the above, unclosed heregexes also used to pass through the lexer
and not error until in the parsing phase, which resulted in confusing error
messages. This has been fixed, too.
- Fix #3348, by adding passing tests.
- Fix #3529: If a string starts with an interpolation, an empty string is no
longer emitted before the interpolation (unless it is needed to coerce the
interpolation into a string).
- Block comments cannot contain `*/`. Now the error message also shows exactly
where the offending `*/`. This improvement might seem unrelated, but I had to
touch that code anyway to refactor string and regex related code, and the
change was very trivial. Moreover, it's consistent with the next two points.
- Regexes cannot start with `*`. Now the error message also shows exactly where
the offending `*` is. (It might actually not be exatly at the start in
heregexes.) It is a very minor improvement, but it was trivial to add.
- Octal escapes in strings are forbidden in CoffeeScript (just like in
JavaScript strict mode). However, this used to be the case only for regular
strings. Now they are also forbidden in heredocs. Moreover, the errors now
point at the offending octal escape.
- Invalid regex flags are no longer allowed. This includes repeated modifiers
and unknown ones. Moreover, invalid modifiers do not stop a heregex from
being matched, which results in better error messages.
- Fix #3621: `///a#{1}///` compiles to `RegExp("a" + 1)`. So does
`RegExp("a#{1}")`. Still, those two code snippets used to generate different
tokens, which is a bit weird, but more importantly causes problems for
coffeelint (see clutchski/coffeelint#340). This required lots of tests in
test/location.coffee to be updated. Note that some updates to those tests are
unrelated to this point; some have been updated to be more consistent (I
discovered this because the refactored code happened to be seemingly more
correct).
- Regular regex literals used to erraneously allow newlines to be escaped,
causing invalid JavaScript output. This has been fixed.
- Heregexes may now be completely empty (`//////`), instead of erroring out with
a confusing message.
- Fix #2388: Heredocs and heregexes used to be lexed simply, which meant that
you couldn't nest a heredoc within a heredoc (double-quoted, that is) or a
heregex inside a heregex.
- Fix #2321: If you used division inside interpolation and then a slash later in
the string containing that interpolation, the division slash and the latter
slash was erraneously matched as a regex. This has been fixed.
- Indentation inside interpolations in heredocs no longer affect how much
indentation is removed from each line of the heredoc (which is more
intuitive).
- Whitespace is now correctly trimmed from the start and end of strings in a few
edge cases.
- Last but not least, the lexing of interpolated strings now seems to be more
efficient. For a regular double-quoted string, we used to use a custom
function to find the end of it (taking interpolations and interpolations
within interpolations etc. into account). Then we used to re-find the
interpolations and recursively lex their contents. In effect, the same string
was processed twice, or even more in the case of deeper nesting of
interpolations. Now the same string is processed just once.
- Code duplication between regular strings, heredocs, regular regexes and
heregexes has been reduced.
- The above two points should result in more easily read code, too.
2015-01-03 17:40:43 -05:00
|
|
|
'''
|
2015-02-05 11:23:03 -05:00
|
|
|
assertErrorFormat '''
|
|
|
|
"a
|
|
|
|
#{b} \\1"
|
|
|
|
''', '''
|
|
|
|
[stdin]:2:8: error: octal escape sequences are not allowed \\1
|
|
|
|
#{b} \\1"
|
2015-02-06 04:52:02 -05:00
|
|
|
^\^
|
2015-02-05 11:23:03 -05:00
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
/a\\0\\tb\\\\\\07c/
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:10: error: octal escape sequences are not allowed \\07
|
|
|
|
/a\\0\\tb\\\\\\07c/
|
2015-02-06 04:52:02 -05:00
|
|
|
\ \ \ \ ^\^^
|
2015-02-05 11:23:03 -05:00
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
///a
|
|
|
|
#{b} \\01///
|
|
|
|
''', '''
|
|
|
|
[stdin]:2:8: error: octal escape sequences are not allowed \\01
|
|
|
|
#{b} \\01///
|
2015-02-06 04:52:02 -05:00
|
|
|
^\^^
|
2015-02-05 11:23:03 -05:00
|
|
|
'''
|
|
|
|
|
|
|
|
test "#3795: invalid escapes", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
"a\\0\\tb\\\\\\x7g"
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:10: error: invalid escape sequence \\x7g
|
|
|
|
"a\\0\\tb\\\\\\x7g"
|
2015-02-06 04:52:02 -05:00
|
|
|
\ \ \ \ ^\^^^
|
2015-02-05 11:23:03 -05:00
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
"a
|
|
|
|
#{b} \\uA02
|
|
|
|
c"
|
|
|
|
''', '''
|
|
|
|
[stdin]:2:8: error: invalid escape sequence \\uA02
|
|
|
|
#{b} \\uA02
|
2015-02-06 04:52:02 -05:00
|
|
|
^\^^^^
|
2015-02-05 11:23:03 -05:00
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
/a\\u002space/
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:3: error: invalid escape sequence \\u002s
|
|
|
|
/a\\u002space/
|
2015-02-06 04:52:02 -05:00
|
|
|
^\^^^^^
|
2015-02-05 11:23:03 -05:00
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
///a \\u002 0 space///
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:6: error: invalid escape sequence \\u002
|
|
|
|
///a \\u002 0 space///
|
2015-02-06 04:52:02 -05:00
|
|
|
^\^^^^^
|
2015-02-05 11:23:03 -05:00
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
///a
|
|
|
|
#{b} \\x0
|
|
|
|
c///
|
|
|
|
''', '''
|
|
|
|
[stdin]:2:8: error: invalid escape sequence \\x0
|
|
|
|
#{b} \\x0
|
2015-02-06 04:52:02 -05:00
|
|
|
^\^^
|
2015-02-05 11:23:03 -05:00
|
|
|
'''
|
2015-02-12 13:26:41 -05:00
|
|
|
assertErrorFormat '''
|
|
|
|
/ab\\u/
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:4: error: invalid escape sequence \\u
|
|
|
|
/ab\\u/
|
|
|
|
^\^
|
|
|
|
'''
|
Refactor interpolation (and string and regex) handling in lexer
- Fix #3394: Unclosed single-quoted strings (both regular ones and heredocs)
used to pass through the lexer, causing a parsing error later, while
double-quoted strings caused an error already in the lexing phase. Now both
single and double-quoted unclosed strings error out in the lexer (which is the
more logical option) with consistent error messages. This also fixes the last
comment by @satyr in #3301.
- Similar to the above, unclosed heregexes also used to pass through the lexer
and not error until in the parsing phase, which resulted in confusing error
messages. This has been fixed, too.
- Fix #3348, by adding passing tests.
- Fix #3529: If a string starts with an interpolation, an empty string is no
longer emitted before the interpolation (unless it is needed to coerce the
interpolation into a string).
- Block comments cannot contain `*/`. Now the error message also shows exactly
where the offending `*/`. This improvement might seem unrelated, but I had to
touch that code anyway to refactor string and regex related code, and the
change was very trivial. Moreover, it's consistent with the next two points.
- Regexes cannot start with `*`. Now the error message also shows exactly where
the offending `*` is. (It might actually not be exatly at the start in
heregexes.) It is a very minor improvement, but it was trivial to add.
- Octal escapes in strings are forbidden in CoffeeScript (just like in
JavaScript strict mode). However, this used to be the case only for regular
strings. Now they are also forbidden in heredocs. Moreover, the errors now
point at the offending octal escape.
- Invalid regex flags are no longer allowed. This includes repeated modifiers
and unknown ones. Moreover, invalid modifiers do not stop a heregex from
being matched, which results in better error messages.
- Fix #3621: `///a#{1}///` compiles to `RegExp("a" + 1)`. So does
`RegExp("a#{1}")`. Still, those two code snippets used to generate different
tokens, which is a bit weird, but more importantly causes problems for
coffeelint (see clutchski/coffeelint#340). This required lots of tests in
test/location.coffee to be updated. Note that some updates to those tests are
unrelated to this point; some have been updated to be more consistent (I
discovered this because the refactored code happened to be seemingly more
correct).
- Regular regex literals used to erraneously allow newlines to be escaped,
causing invalid JavaScript output. This has been fixed.
- Heregexes may now be completely empty (`//////`), instead of erroring out with
a confusing message.
- Fix #2388: Heredocs and heregexes used to be lexed simply, which meant that
you couldn't nest a heredoc within a heredoc (double-quoted, that is) or a
heregex inside a heregex.
- Fix #2321: If you used division inside interpolation and then a slash later in
the string containing that interpolation, the division slash and the latter
slash was erraneously matched as a regex. This has been fixed.
- Indentation inside interpolations in heredocs no longer affect how much
indentation is removed from each line of the heredoc (which is more
intuitive).
- Whitespace is now correctly trimmed from the start and end of strings in a few
edge cases.
- Last but not least, the lexing of interpolated strings now seems to be more
efficient. For a regular double-quoted string, we used to use a custom
function to find the end of it (taking interpolations and interpolations
within interpolations etc. into account). Then we used to re-find the
interpolations and recursively lex their contents. In effect, the same string
was processed twice, or even more in the case of deeper nesting of
interpolations. Now the same string is processed just once.
- Code duplication between regular strings, heredocs, regular regexes and
heregexes has been reduced.
- The above two points should result in more easily read code, too.
2015-01-03 17:40:43 -05:00
|
|
|
|
|
|
|
test "illegal herecomment", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
###
|
|
|
|
Regex: /a*/g
|
|
|
|
###
|
|
|
|
''', '''
|
|
|
|
[stdin]:2:12: error: block comments cannot contain */
|
|
|
|
Regex: /a*/g
|
2015-02-06 04:52:02 -05:00
|
|
|
^^
|
Refactor interpolation (and string and regex) handling in lexer
- Fix #3394: Unclosed single-quoted strings (both regular ones and heredocs)
used to pass through the lexer, causing a parsing error later, while
double-quoted strings caused an error already in the lexing phase. Now both
single and double-quoted unclosed strings error out in the lexer (which is the
more logical option) with consistent error messages. This also fixes the last
comment by @satyr in #3301.
- Similar to the above, unclosed heregexes also used to pass through the lexer
and not error until in the parsing phase, which resulted in confusing error
messages. This has been fixed, too.
- Fix #3348, by adding passing tests.
- Fix #3529: If a string starts with an interpolation, an empty string is no
longer emitted before the interpolation (unless it is needed to coerce the
interpolation into a string).
- Block comments cannot contain `*/`. Now the error message also shows exactly
where the offending `*/`. This improvement might seem unrelated, but I had to
touch that code anyway to refactor string and regex related code, and the
change was very trivial. Moreover, it's consistent with the next two points.
- Regexes cannot start with `*`. Now the error message also shows exactly where
the offending `*` is. (It might actually not be exatly at the start in
heregexes.) It is a very minor improvement, but it was trivial to add.
- Octal escapes in strings are forbidden in CoffeeScript (just like in
JavaScript strict mode). However, this used to be the case only for regular
strings. Now they are also forbidden in heredocs. Moreover, the errors now
point at the offending octal escape.
- Invalid regex flags are no longer allowed. This includes repeated modifiers
and unknown ones. Moreover, invalid modifiers do not stop a heregex from
being matched, which results in better error messages.
- Fix #3621: `///a#{1}///` compiles to `RegExp("a" + 1)`. So does
`RegExp("a#{1}")`. Still, those two code snippets used to generate different
tokens, which is a bit weird, but more importantly causes problems for
coffeelint (see clutchski/coffeelint#340). This required lots of tests in
test/location.coffee to be updated. Note that some updates to those tests are
unrelated to this point; some have been updated to be more consistent (I
discovered this because the refactored code happened to be seemingly more
correct).
- Regular regex literals used to erraneously allow newlines to be escaped,
causing invalid JavaScript output. This has been fixed.
- Heregexes may now be completely empty (`//////`), instead of erroring out with
a confusing message.
- Fix #2388: Heredocs and heregexes used to be lexed simply, which meant that
you couldn't nest a heredoc within a heredoc (double-quoted, that is) or a
heregex inside a heregex.
- Fix #2321: If you used division inside interpolation and then a slash later in
the string containing that interpolation, the division slash and the latter
slash was erraneously matched as a regex. This has been fixed.
- Indentation inside interpolations in heredocs no longer affect how much
indentation is removed from each line of the heredoc (which is more
intuitive).
- Whitespace is now correctly trimmed from the start and end of strings in a few
edge cases.
- Last but not least, the lexing of interpolated strings now seems to be more
efficient. For a regular double-quoted string, we used to use a custom
function to find the end of it (taking interpolations and interpolations
within interpolations etc. into account). Then we used to re-find the
interpolations and recursively lex their contents. In effect, the same string
was processed twice, or even more in the case of deeper nesting of
interpolations. Now the same string is processed just once.
- Code duplication between regular strings, heredocs, regular regexes and
heregexes has been reduced.
- The above two points should result in more easily read code, too.
2015-01-03 17:40:43 -05:00
|
|
|
'''
|
|
|
|
|
|
|
|
test "#1724: regular expressions beginning with *", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
/* foo/
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:2: error: regular expressions cannot begin with *
|
|
|
|
/* foo/
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
///
|
|
|
|
* foo
|
|
|
|
///
|
|
|
|
''', '''
|
|
|
|
[stdin]:2:3: error: regular expressions cannot begin with *
|
|
|
|
* foo
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
|
|
|
|
test "invalid regex flags", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
/a/ii
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:4: error: invalid regular expression flags ii
|
|
|
|
/a/ii
|
2015-02-06 04:52:02 -05:00
|
|
|
^^
|
Refactor interpolation (and string and regex) handling in lexer
- Fix #3394: Unclosed single-quoted strings (both regular ones and heredocs)
used to pass through the lexer, causing a parsing error later, while
double-quoted strings caused an error already in the lexing phase. Now both
single and double-quoted unclosed strings error out in the lexer (which is the
more logical option) with consistent error messages. This also fixes the last
comment by @satyr in #3301.
- Similar to the above, unclosed heregexes also used to pass through the lexer
and not error until in the parsing phase, which resulted in confusing error
messages. This has been fixed, too.
- Fix #3348, by adding passing tests.
- Fix #3529: If a string starts with an interpolation, an empty string is no
longer emitted before the interpolation (unless it is needed to coerce the
interpolation into a string).
- Block comments cannot contain `*/`. Now the error message also shows exactly
where the offending `*/`. This improvement might seem unrelated, but I had to
touch that code anyway to refactor string and regex related code, and the
change was very trivial. Moreover, it's consistent with the next two points.
- Regexes cannot start with `*`. Now the error message also shows exactly where
the offending `*` is. (It might actually not be exatly at the start in
heregexes.) It is a very minor improvement, but it was trivial to add.
- Octal escapes in strings are forbidden in CoffeeScript (just like in
JavaScript strict mode). However, this used to be the case only for regular
strings. Now they are also forbidden in heredocs. Moreover, the errors now
point at the offending octal escape.
- Invalid regex flags are no longer allowed. This includes repeated modifiers
and unknown ones. Moreover, invalid modifiers do not stop a heregex from
being matched, which results in better error messages.
- Fix #3621: `///a#{1}///` compiles to `RegExp("a" + 1)`. So does
`RegExp("a#{1}")`. Still, those two code snippets used to generate different
tokens, which is a bit weird, but more importantly causes problems for
coffeelint (see clutchski/coffeelint#340). This required lots of tests in
test/location.coffee to be updated. Note that some updates to those tests are
unrelated to this point; some have been updated to be more consistent (I
discovered this because the refactored code happened to be seemingly more
correct).
- Regular regex literals used to erraneously allow newlines to be escaped,
causing invalid JavaScript output. This has been fixed.
- Heregexes may now be completely empty (`//////`), instead of erroring out with
a confusing message.
- Fix #2388: Heredocs and heregexes used to be lexed simply, which meant that
you couldn't nest a heredoc within a heredoc (double-quoted, that is) or a
heregex inside a heregex.
- Fix #2321: If you used division inside interpolation and then a slash later in
the string containing that interpolation, the division slash and the latter
slash was erraneously matched as a regex. This has been fixed.
- Indentation inside interpolations in heredocs no longer affect how much
indentation is removed from each line of the heredoc (which is more
intuitive).
- Whitespace is now correctly trimmed from the start and end of strings in a few
edge cases.
- Last but not least, the lexing of interpolated strings now seems to be more
efficient. For a regular double-quoted string, we used to use a custom
function to find the end of it (taking interpolations and interpolations
within interpolations etc. into account). Then we used to re-find the
interpolations and recursively lex their contents. In effect, the same string
was processed twice, or even more in the case of deeper nesting of
interpolations. Now the same string is processed just once.
- Code duplication between regular strings, heredocs, regular regexes and
heregexes has been reduced.
- The above two points should result in more easily read code, too.
2015-01-03 17:40:43 -05:00
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
/a/G
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:4: error: invalid regular expression flags G
|
|
|
|
/a/G
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
/a/gimi
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:4: error: invalid regular expression flags gimi
|
|
|
|
/a/gimi
|
2015-02-06 04:52:02 -05:00
|
|
|
^^^^
|
Refactor interpolation (and string and regex) handling in lexer
- Fix #3394: Unclosed single-quoted strings (both regular ones and heredocs)
used to pass through the lexer, causing a parsing error later, while
double-quoted strings caused an error already in the lexing phase. Now both
single and double-quoted unclosed strings error out in the lexer (which is the
more logical option) with consistent error messages. This also fixes the last
comment by @satyr in #3301.
- Similar to the above, unclosed heregexes also used to pass through the lexer
and not error until in the parsing phase, which resulted in confusing error
messages. This has been fixed, too.
- Fix #3348, by adding passing tests.
- Fix #3529: If a string starts with an interpolation, an empty string is no
longer emitted before the interpolation (unless it is needed to coerce the
interpolation into a string).
- Block comments cannot contain `*/`. Now the error message also shows exactly
where the offending `*/`. This improvement might seem unrelated, but I had to
touch that code anyway to refactor string and regex related code, and the
change was very trivial. Moreover, it's consistent with the next two points.
- Regexes cannot start with `*`. Now the error message also shows exactly where
the offending `*` is. (It might actually not be exatly at the start in
heregexes.) It is a very minor improvement, but it was trivial to add.
- Octal escapes in strings are forbidden in CoffeeScript (just like in
JavaScript strict mode). However, this used to be the case only for regular
strings. Now they are also forbidden in heredocs. Moreover, the errors now
point at the offending octal escape.
- Invalid regex flags are no longer allowed. This includes repeated modifiers
and unknown ones. Moreover, invalid modifiers do not stop a heregex from
being matched, which results in better error messages.
- Fix #3621: `///a#{1}///` compiles to `RegExp("a" + 1)`. So does
`RegExp("a#{1}")`. Still, those two code snippets used to generate different
tokens, which is a bit weird, but more importantly causes problems for
coffeelint (see clutchski/coffeelint#340). This required lots of tests in
test/location.coffee to be updated. Note that some updates to those tests are
unrelated to this point; some have been updated to be more consistent (I
discovered this because the refactored code happened to be seemingly more
correct).
- Regular regex literals used to erraneously allow newlines to be escaped,
causing invalid JavaScript output. This has been fixed.
- Heregexes may now be completely empty (`//////`), instead of erroring out with
a confusing message.
- Fix #2388: Heredocs and heregexes used to be lexed simply, which meant that
you couldn't nest a heredoc within a heredoc (double-quoted, that is) or a
heregex inside a heregex.
- Fix #2321: If you used division inside interpolation and then a slash later in
the string containing that interpolation, the division slash and the latter
slash was erraneously matched as a regex. This has been fixed.
- Indentation inside interpolations in heredocs no longer affect how much
indentation is removed from each line of the heredoc (which is more
intuitive).
- Whitespace is now correctly trimmed from the start and end of strings in a few
edge cases.
- Last but not least, the lexing of interpolated strings now seems to be more
efficient. For a regular double-quoted string, we used to use a custom
function to find the end of it (taking interpolations and interpolations
within interpolations etc. into account). Then we used to re-find the
interpolations and recursively lex their contents. In effect, the same string
was processed twice, or even more in the case of deeper nesting of
interpolations. Now the same string is processed just once.
- Code duplication between regular strings, heredocs, regular regexes and
heregexes has been reduced.
- The above two points should result in more easily read code, too.
2015-01-03 17:40:43 -05:00
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
/a/g_
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:4: error: invalid regular expression flags g_
|
|
|
|
/a/g_
|
2015-02-06 04:52:02 -05:00
|
|
|
^^
|
Refactor interpolation (and string and regex) handling in lexer
- Fix #3394: Unclosed single-quoted strings (both regular ones and heredocs)
used to pass through the lexer, causing a parsing error later, while
double-quoted strings caused an error already in the lexing phase. Now both
single and double-quoted unclosed strings error out in the lexer (which is the
more logical option) with consistent error messages. This also fixes the last
comment by @satyr in #3301.
- Similar to the above, unclosed heregexes also used to pass through the lexer
and not error until in the parsing phase, which resulted in confusing error
messages. This has been fixed, too.
- Fix #3348, by adding passing tests.
- Fix #3529: If a string starts with an interpolation, an empty string is no
longer emitted before the interpolation (unless it is needed to coerce the
interpolation into a string).
- Block comments cannot contain `*/`. Now the error message also shows exactly
where the offending `*/`. This improvement might seem unrelated, but I had to
touch that code anyway to refactor string and regex related code, and the
change was very trivial. Moreover, it's consistent with the next two points.
- Regexes cannot start with `*`. Now the error message also shows exactly where
the offending `*` is. (It might actually not be exatly at the start in
heregexes.) It is a very minor improvement, but it was trivial to add.
- Octal escapes in strings are forbidden in CoffeeScript (just like in
JavaScript strict mode). However, this used to be the case only for regular
strings. Now they are also forbidden in heredocs. Moreover, the errors now
point at the offending octal escape.
- Invalid regex flags are no longer allowed. This includes repeated modifiers
and unknown ones. Moreover, invalid modifiers do not stop a heregex from
being matched, which results in better error messages.
- Fix #3621: `///a#{1}///` compiles to `RegExp("a" + 1)`. So does
`RegExp("a#{1}")`. Still, those two code snippets used to generate different
tokens, which is a bit weird, but more importantly causes problems for
coffeelint (see clutchski/coffeelint#340). This required lots of tests in
test/location.coffee to be updated. Note that some updates to those tests are
unrelated to this point; some have been updated to be more consistent (I
discovered this because the refactored code happened to be seemingly more
correct).
- Regular regex literals used to erraneously allow newlines to be escaped,
causing invalid JavaScript output. This has been fixed.
- Heregexes may now be completely empty (`//////`), instead of erroring out with
a confusing message.
- Fix #2388: Heredocs and heregexes used to be lexed simply, which meant that
you couldn't nest a heredoc within a heredoc (double-quoted, that is) or a
heregex inside a heregex.
- Fix #2321: If you used division inside interpolation and then a slash later in
the string containing that interpolation, the division slash and the latter
slash was erraneously matched as a regex. This has been fixed.
- Indentation inside interpolations in heredocs no longer affect how much
indentation is removed from each line of the heredoc (which is more
intuitive).
- Whitespace is now correctly trimmed from the start and end of strings in a few
edge cases.
- Last but not least, the lexing of interpolated strings now seems to be more
efficient. For a regular double-quoted string, we used to use a custom
function to find the end of it (taking interpolations and interpolations
within interpolations etc. into account). Then we used to re-find the
interpolations and recursively lex their contents. In effect, the same string
was processed twice, or even more in the case of deeper nesting of
interpolations. Now the same string is processed just once.
- Code duplication between regular strings, heredocs, regular regexes and
heregexes has been reduced.
- The above two points should result in more easily read code, too.
2015-01-03 17:40:43 -05:00
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
///a///ii
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:8: error: invalid regular expression flags ii
|
|
|
|
///a///ii
|
2015-02-06 04:52:02 -05:00
|
|
|
^^
|
Refactor interpolation (and string and regex) handling in lexer
- Fix #3394: Unclosed single-quoted strings (both regular ones and heredocs)
used to pass through the lexer, causing a parsing error later, while
double-quoted strings caused an error already in the lexing phase. Now both
single and double-quoted unclosed strings error out in the lexer (which is the
more logical option) with consistent error messages. This also fixes the last
comment by @satyr in #3301.
- Similar to the above, unclosed heregexes also used to pass through the lexer
and not error until in the parsing phase, which resulted in confusing error
messages. This has been fixed, too.
- Fix #3348, by adding passing tests.
- Fix #3529: If a string starts with an interpolation, an empty string is no
longer emitted before the interpolation (unless it is needed to coerce the
interpolation into a string).
- Block comments cannot contain `*/`. Now the error message also shows exactly
where the offending `*/`. This improvement might seem unrelated, but I had to
touch that code anyway to refactor string and regex related code, and the
change was very trivial. Moreover, it's consistent with the next two points.
- Regexes cannot start with `*`. Now the error message also shows exactly where
the offending `*` is. (It might actually not be exatly at the start in
heregexes.) It is a very minor improvement, but it was trivial to add.
- Octal escapes in strings are forbidden in CoffeeScript (just like in
JavaScript strict mode). However, this used to be the case only for regular
strings. Now they are also forbidden in heredocs. Moreover, the errors now
point at the offending octal escape.
- Invalid regex flags are no longer allowed. This includes repeated modifiers
and unknown ones. Moreover, invalid modifiers do not stop a heregex from
being matched, which results in better error messages.
- Fix #3621: `///a#{1}///` compiles to `RegExp("a" + 1)`. So does
`RegExp("a#{1}")`. Still, those two code snippets used to generate different
tokens, which is a bit weird, but more importantly causes problems for
coffeelint (see clutchski/coffeelint#340). This required lots of tests in
test/location.coffee to be updated. Note that some updates to those tests are
unrelated to this point; some have been updated to be more consistent (I
discovered this because the refactored code happened to be seemingly more
correct).
- Regular regex literals used to erraneously allow newlines to be escaped,
causing invalid JavaScript output. This has been fixed.
- Heregexes may now be completely empty (`//////`), instead of erroring out with
a confusing message.
- Fix #2388: Heredocs and heregexes used to be lexed simply, which meant that
you couldn't nest a heredoc within a heredoc (double-quoted, that is) or a
heregex inside a heregex.
- Fix #2321: If you used division inside interpolation and then a slash later in
the string containing that interpolation, the division slash and the latter
slash was erraneously matched as a regex. This has been fixed.
- Indentation inside interpolations in heredocs no longer affect how much
indentation is removed from each line of the heredoc (which is more
intuitive).
- Whitespace is now correctly trimmed from the start and end of strings in a few
edge cases.
- Last but not least, the lexing of interpolated strings now seems to be more
efficient. For a regular double-quoted string, we used to use a custom
function to find the end of it (taking interpolations and interpolations
within interpolations etc. into account). Then we used to re-find the
interpolations and recursively lex their contents. In effect, the same string
was processed twice, or even more in the case of deeper nesting of
interpolations. Now the same string is processed just once.
- Code duplication between regular strings, heredocs, regular regexes and
heregexes has been reduced.
- The above two points should result in more easily read code, too.
2015-01-03 17:40:43 -05:00
|
|
|
'''
|
|
|
|
doesNotThrow -> CoffeeScript.compile '/a/ymgi'
|
2015-01-03 18:28:23 -05:00
|
|
|
|
|
|
|
test "missing `)`, `}`, `]`", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
(
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:1: error: missing )
|
|
|
|
(
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
{
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:1: error: missing }
|
|
|
|
{
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
[
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:1: error: missing ]
|
|
|
|
[
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
obj = {a: [1, (2+
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:15: error: missing )
|
|
|
|
obj = {a: [1, (2+
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
"#{
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:3: error: missing }
|
|
|
|
"#{
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
"""
|
|
|
|
foo#{ bar "#{1}"
|
|
|
|
''', '''
|
|
|
|
[stdin]:2:7: error: missing }
|
|
|
|
foo#{ bar "#{1}"
|
|
|
|
^
|
|
|
|
'''
|
2015-01-09 19:48:00 -05:00
|
|
|
|
|
|
|
test "unclosed regexes", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
/
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:1: error: missing / (unclosed regex)
|
|
|
|
/
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
# Note the double escaping; this would be `/a\/` real code.
|
|
|
|
/a\\/
|
|
|
|
''', '''
|
|
|
|
[stdin]:2:1: error: missing / (unclosed regex)
|
|
|
|
/a\\/
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
/// ^
|
|
|
|
a #{""" ""#{if /[/].test "|" then 1 else 0}"" """}
|
|
|
|
///
|
|
|
|
''', '''
|
|
|
|
[stdin]:2:18: error: missing / (unclosed regex)
|
|
|
|
a #{""" ""#{if /[/].test "|" then 1 else 0}"" """}
|
|
|
|
^
|
|
|
|
'''
|
Fix #1500, #1574, #3318: Name generated vars uniquely
Any variables generated by CoffeeScript are now made sure to be named to
something not present in the source code being compiled. This way you can no
longer interfere with them, either on purpose or by mistake. (#1500, #1574)
For example, `({a}, _arg) ->` now compiles correctly. (#1574)
As opposed to the somewhat complex implementations discussed in #1500, this
commit takes a very simple approach by saving all used variables names using a
single pass over the token stream. Any generated variables are then made sure
not to exist in that list.
`(@a) -> a` used to be equivalent to `(@a) -> @a`, but now throws a runtime
`ReferenceError` instead (unless `a` exists in an upper scope of course). (#3318)
`(@a) ->` used to compile to `(function(a) { this.a = a; })`. Now it compiles to
`(function(_at_a) { this.a = _at_a; })`. (But you cannot access `_at_a` either,
of course.)
Because of the above, `(@a, a) ->` is now valid; `@a` and `a` are not duplicate
parameters.
Duplicate this-parameters with a reserved word, such as `(@case, @case) ->`,
used to compile but now throws, just like regular duplicate parameters.
2015-01-10 17:04:30 -05:00
|
|
|
|
|
|
|
test "duplicate function arguments", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
(foo, bar, foo) ->
|
|
|
|
''', '''
|
2016-09-25 02:23:24 -04:00
|
|
|
[stdin]:1:12: error: multiple parameters named 'foo'
|
Fix #1500, #1574, #3318: Name generated vars uniquely
Any variables generated by CoffeeScript are now made sure to be named to
something not present in the source code being compiled. This way you can no
longer interfere with them, either on purpose or by mistake. (#1500, #1574)
For example, `({a}, _arg) ->` now compiles correctly. (#1574)
As opposed to the somewhat complex implementations discussed in #1500, this
commit takes a very simple approach by saving all used variables names using a
single pass over the token stream. Any generated variables are then made sure
not to exist in that list.
`(@a) -> a` used to be equivalent to `(@a) -> @a`, but now throws a runtime
`ReferenceError` instead (unless `a` exists in an upper scope of course). (#3318)
`(@a) ->` used to compile to `(function(a) { this.a = a; })`. Now it compiles to
`(function(_at_a) { this.a = _at_a; })`. (But you cannot access `_at_a` either,
of course.)
Because of the above, `(@a, a) ->` is now valid; `@a` and `a` are not duplicate
parameters.
Duplicate this-parameters with a reserved word, such as `(@case, @case) ->`,
used to compile but now throws, just like regular duplicate parameters.
2015-01-10 17:04:30 -05:00
|
|
|
(foo, bar, foo) ->
|
|
|
|
^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
(@foo, bar, @foo) ->
|
|
|
|
''', '''
|
2016-09-25 02:23:24 -04:00
|
|
|
[stdin]:1:13: error: multiple parameters named '@foo'
|
Fix #1500, #1574, #3318: Name generated vars uniquely
Any variables generated by CoffeeScript are now made sure to be named to
something not present in the source code being compiled. This way you can no
longer interfere with them, either on purpose or by mistake. (#1500, #1574)
For example, `({a}, _arg) ->` now compiles correctly. (#1574)
As opposed to the somewhat complex implementations discussed in #1500, this
commit takes a very simple approach by saving all used variables names using a
single pass over the token stream. Any generated variables are then made sure
not to exist in that list.
`(@a) -> a` used to be equivalent to `(@a) -> @a`, but now throws a runtime
`ReferenceError` instead (unless `a` exists in an upper scope of course). (#3318)
`(@a) ->` used to compile to `(function(a) { this.a = a; })`. Now it compiles to
`(function(_at_a) { this.a = _at_a; })`. (But you cannot access `_at_a` either,
of course.)
Because of the above, `(@a, a) ->` is now valid; `@a` and `a` are not duplicate
parameters.
Duplicate this-parameters with a reserved word, such as `(@case, @case) ->`,
used to compile but now throws, just like regular duplicate parameters.
2015-01-10 17:04:30 -05:00
|
|
|
(@foo, bar, @foo) ->
|
|
|
|
^^^^
|
|
|
|
'''
|
2015-02-06 04:52:02 -05:00
|
|
|
|
|
|
|
test "reserved words", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
case
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:1: error: reserved word 'case'
|
|
|
|
case
|
|
|
|
^^^^
|
|
|
|
'''
|
2016-03-05 14:59:39 -05:00
|
|
|
assertErrorFormat '''
|
|
|
|
case = 1
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:1: error: reserved word 'case'
|
|
|
|
case = 1
|
|
|
|
^^^^
|
|
|
|
'''
|
2015-02-06 04:52:02 -05:00
|
|
|
assertErrorFormat '''
|
|
|
|
for = 1
|
|
|
|
''', '''
|
2016-03-05 14:59:39 -05:00
|
|
|
[stdin]:1:1: error: keyword 'for' can't be assigned
|
2015-02-06 04:52:02 -05:00
|
|
|
for = 1
|
|
|
|
^^^
|
|
|
|
'''
|
2016-03-05 14:59:39 -05:00
|
|
|
assertErrorFormat '''
|
|
|
|
unless = 1
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:1: error: keyword 'unless' can't be assigned
|
|
|
|
unless = 1
|
|
|
|
^^^^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
for += 1
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:1: error: keyword 'for' can't be assigned
|
|
|
|
for += 1
|
|
|
|
^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
for &&= 1
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:1: error: keyword 'for' can't be assigned
|
|
|
|
for &&= 1
|
|
|
|
^^^
|
|
|
|
'''
|
|
|
|
# Make sure token look-behind doesn't go out of range.
|
|
|
|
assertErrorFormat '''
|
|
|
|
&&= 1
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:1: error: unexpected &&=
|
|
|
|
&&= 1
|
|
|
|
^^^
|
|
|
|
'''
|
2015-05-01 08:33:11 -04:00
|
|
|
# #2306: Show unaliased name in error messages.
|
|
|
|
assertErrorFormat '''
|
|
|
|
on = 1
|
|
|
|
''', '''
|
2016-03-05 14:59:39 -05:00
|
|
|
[stdin]:1:1: error: keyword 'on' can't be assigned
|
2015-05-01 08:33:11 -04:00
|
|
|
on = 1
|
|
|
|
^^
|
|
|
|
'''
|
2015-02-06 04:52:02 -05:00
|
|
|
|
2016-03-05 14:59:39 -05:00
|
|
|
test "strict mode errors", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
eval = 1
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:1: error: 'eval' can't be assigned
|
|
|
|
eval = 1
|
|
|
|
^^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
class eval
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:7: error: 'eval' can't be assigned
|
|
|
|
class eval
|
|
|
|
^^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
arguments++
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:1: error: 'arguments' can't be assigned
|
|
|
|
arguments++
|
|
|
|
^^^^^^^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
--arguments
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:3: error: 'arguments' can't be assigned
|
|
|
|
--arguments
|
|
|
|
^^^^^^^^^
|
|
|
|
'''
|
|
|
|
|
2015-02-06 04:52:02 -05:00
|
|
|
test "invalid numbers", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
0X0
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:2: error: radix prefix in '0X0' must be lowercase
|
|
|
|
0X0
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
10E0
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:3: error: exponential notation in '10E0' must be indicated with a lowercase 'e'
|
|
|
|
10E0
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
018
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:1: error: decimal literal '018' must not be prefixed with '0'
|
|
|
|
018
|
|
|
|
^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
010
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:1: error: octal literal '010' must be prefixed with '0o'
|
|
|
|
010
|
|
|
|
^^^
|
Fix #3597: Allow interpolations in object keys
The following is now allowed:
o =
a: 1
b: 2
"#{'c'}": 3
"#{'d'}": 4
e: 5
"#{'f'}": 6
g: 7
It compiles to:
o = (
obj = {
a: 1,
b: 2
},
obj["" + 'c'] = 3,
obj["" + 'd'] = 4,
obj.e = 5,
obj["" + 'f'] = 6,
obj.g = 7,
obj
);
- Closes #3039. Empty interpolations in object keys are now _supposed_ to be
allowed.
- Closes #1131. No need to improve error messages for attempted key
interpolation anymore.
- Implementing this required fixing the following bug: `("" + a): 1` used to
error out on the colon, saying "unexpected colon". But really, it is the
attempted object key that is unexpected. Now the error is on the opening
parenthesis instead.
- However, the above fix broke some error message tests for regexes. The easiest
way to fix this was to make a seemingly unrelated change: The error messages
for unexpected identifiers, numbers, strings and regexes now say for example
'unexpected string' instead of 'unexpected """some #{really long} string"""'.
In other words, the tag _name_ is used instead of the tag _value_.
This was way easier to implement, and is more helpful to the user. Using the
tag value is good for operators, reserved words and the like, but not for
tokens which can contain any text. For example, 'unexpected identifier' is
better than 'unexpected expected' (if a variable called 'expected' was used
erraneously).
- While writing tests for the above point I found a few minor bugs with string
locations which have been fixed.
2015-02-07 14:16:59 -05:00
|
|
|
'''
|
|
|
|
|
|
|
|
test "unexpected object keys", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
{[[]]}
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:2: error: unexpected [
|
|
|
|
{[[]]}
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
{[[]]: 1}
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:2: error: unexpected [
|
|
|
|
{[[]]: 1}
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
[[]]: 1
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:1: error: unexpected [
|
|
|
|
[[]]: 1
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
{(a + "b")}
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:2: error: unexpected (
|
|
|
|
{(a + "b")}
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
{(a + "b"): 1}
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:2: error: unexpected (
|
|
|
|
{(a + "b"): 1}
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
(a + "b"): 1
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:1: error: unexpected (
|
|
|
|
(a + "b"): 1
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
a: 1, [[]]: 2
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:7: error: unexpected [
|
|
|
|
a: 1, [[]]: 2
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
{a: 1, [[]]: 2}
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:8: error: unexpected [
|
|
|
|
{a: 1, [[]]: 2}
|
|
|
|
^
|
2015-02-06 04:52:02 -05:00
|
|
|
'''
|
2015-05-01 05:58:37 -04:00
|
|
|
|
|
|
|
test "invalid object keys", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
@a: 1
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:1: error: invalid object key
|
|
|
|
@a: 1
|
|
|
|
^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
f
|
|
|
|
@a: 1
|
|
|
|
''', '''
|
|
|
|
[stdin]:2:3: error: invalid object key
|
|
|
|
@a: 1
|
|
|
|
^^
|
|
|
|
'''
|
2015-08-22 15:39:26 -04:00
|
|
|
assertErrorFormat '''
|
|
|
|
{a=2}
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:3: error: unexpected =
|
|
|
|
{a=2}
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
|
|
|
|
test "invalid destructuring default target", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
{'a' = 2} = obj
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:6: error: unexpected =
|
|
|
|
{'a' = 2} = obj
|
|
|
|
^
|
|
|
|
'''
|
2015-08-25 13:19:21 -04:00
|
|
|
|
|
|
|
test "#4070: lone expansion", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
[...] = a
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:2: error: Destructuring assignment has no target
|
|
|
|
[...] = a
|
|
|
|
^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
[ ..., ] = a
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:3: error: Destructuring assignment has no target
|
|
|
|
[ ..., ] = a
|
|
|
|
^^^
|
|
|
|
'''
|
2015-08-28 17:11:47 -04:00
|
|
|
|
|
|
|
test "#3926: implicit object in parameter list", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
(a: b) ->
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:3: error: unexpected :
|
|
|
|
(a: b) ->
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
(one, two, {three, four: five}, key: value) ->
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:36: error: unexpected :
|
|
|
|
(one, two, {three, four: five}, key: value) ->
|
|
|
|
^
|
|
|
|
'''
|
2015-09-16 01:51:17 -04:00
|
|
|
|
2015-10-22 11:26:11 -04:00
|
|
|
test "#4130: unassignable in destructured param", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
fun = ({
|
|
|
|
@param : null
|
|
|
|
}) ->
|
|
|
|
console.log "Oh hello!"
|
|
|
|
''', '''
|
2016-03-05 14:59:39 -05:00
|
|
|
[stdin]:2:12: error: keyword 'null' can't be assigned
|
2015-10-22 11:26:11 -04:00
|
|
|
@param : null
|
|
|
|
^^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
({a: null}) ->
|
|
|
|
''', '''
|
2016-03-05 14:59:39 -05:00
|
|
|
[stdin]:1:6: error: keyword 'null' can't be assigned
|
2015-10-22 11:26:11 -04:00
|
|
|
({a: null}) ->
|
|
|
|
^^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
({a: 1}) ->
|
|
|
|
''', '''
|
2016-03-05 14:59:39 -05:00
|
|
|
[stdin]:1:6: error: '1' can't be assigned
|
2015-10-22 11:26:11 -04:00
|
|
|
({a: 1}) ->
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
({1}) ->
|
|
|
|
''', '''
|
2016-03-05 14:59:39 -05:00
|
|
|
[stdin]:1:3: error: '1' can't be assigned
|
2015-10-22 11:26:11 -04:00
|
|
|
({1}) ->
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
({a: true = 1}) ->
|
|
|
|
''', '''
|
2016-03-05 14:59:39 -05:00
|
|
|
[stdin]:1:6: error: keyword 'true' can't be assigned
|
2015-10-22 11:26:11 -04:00
|
|
|
({a: true = 1}) ->
|
|
|
|
^^^^
|
|
|
|
'''
|
|
|
|
|
2015-09-16 01:51:17 -04:00
|
|
|
test "`yield` outside of a function", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
yield 1
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:1: error: yield can only occur inside functions
|
|
|
|
yield 1
|
|
|
|
^^^^^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
yield return
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:1: error: yield can only occur inside functions
|
|
|
|
yield return
|
|
|
|
^^^^^^^^^^^^
|
|
|
|
'''
|
|
|
|
|
|
|
|
test "#4097: `yield return` as an expression", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
-> (yield return)
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:5: error: cannot use a pure statement in an expression
|
|
|
|
-> (yield return)
|
|
|
|
^^^^^^^^^^^^
|
|
|
|
'''
|
2016-03-05 14:59:39 -05:00
|
|
|
|
|
|
|
test "`&&=` and `||=` with a space in-between", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
a = 0
|
|
|
|
a && = 1
|
|
|
|
''', '''
|
|
|
|
[stdin]:2:6: error: unexpected =
|
|
|
|
a && = 1
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
a = 0
|
|
|
|
a and = 1
|
|
|
|
''', '''
|
|
|
|
[stdin]:2:7: error: unexpected =
|
|
|
|
a and = 1
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
a = 0
|
|
|
|
a || = 1
|
|
|
|
''', '''
|
|
|
|
[stdin]:2:6: error: unexpected =
|
|
|
|
a || = 1
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
a = 0
|
|
|
|
a or = 1
|
|
|
|
''', '''
|
|
|
|
[stdin]:2:6: error: unexpected =
|
|
|
|
a or = 1
|
|
|
|
^
|
|
|
|
'''
|
Support import and export of ES2015 modules (#4300)
This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages:
```js
import "module-name"
import defaultMember from "module-name"
import * as name from "module-name"
import { } from "module-name"
import { member } from "module-name"
import { member as alias } from "module-name"
import { member1, member2 as alias2, … } from "module-name"
import defaultMember, * as name from "module-name"
import defaultMember, { … } from "module-name"
export default expression
export class name
export { }
export { name }
export { name as exportedName }
export { name as default }
export { name1, name2 as exportedName2, name3 as default, … }
export * from "module-name"
export { … } from "module-name"
```
As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports:
```js
export name = …
```
CoffeeScript also supports optional commas within `{ … }`.
This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this.
This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used.
There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests:
* I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu)
* I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos)
The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 14:46:05 -04:00
|
|
|
|
|
|
|
test "anonymous functions cannot be exported", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
export ->
|
|
|
|
console.log 'hello, world!'
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:8: error: unexpected ->
|
|
|
|
export ->
|
|
|
|
^^
|
|
|
|
'''
|
|
|
|
|
|
|
|
test "anonymous classes cannot be exported", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
export class
|
|
|
|
constructor: ->
|
|
|
|
console.log 'hello, world!'
|
|
|
|
''', '''
|
2016-10-16 00:32:06 -04:00
|
|
|
[stdin]:1:8: error: anonymous classes cannot be exported
|
|
|
|
export class
|
|
|
|
^^^^^
|
Support import and export of ES2015 modules (#4300)
This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages:
```js
import "module-name"
import defaultMember from "module-name"
import * as name from "module-name"
import { } from "module-name"
import { member } from "module-name"
import { member as alias } from "module-name"
import { member1, member2 as alias2, … } from "module-name"
import defaultMember, * as name from "module-name"
import defaultMember, { … } from "module-name"
export default expression
export class name
export { }
export { name }
export { name as exportedName }
export { name as default }
export { name1, name2 as exportedName2, name3 as default, … }
export * from "module-name"
export { … } from "module-name"
```
As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports:
```js
export name = …
```
CoffeeScript also supports optional commas within `{ … }`.
This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this.
This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used.
There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests:
* I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu)
* I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos)
The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 14:46:05 -04:00
|
|
|
'''
|
|
|
|
|
|
|
|
test "unless enclosed by curly braces, only * can be aliased", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
import foo as bar from 'lib'
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:12: error: unexpected as
|
|
|
|
import foo as bar from 'lib'
|
|
|
|
^^
|
|
|
|
'''
|
|
|
|
|
|
|
|
test "unwrapped imports must follow constrained syntax", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
import foo, bar from 'lib'
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:13: error: unexpected identifier
|
|
|
|
import foo, bar from 'lib'
|
|
|
|
^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
import foo, bar, baz from 'lib'
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:13: error: unexpected identifier
|
|
|
|
import foo, bar, baz from 'lib'
|
|
|
|
^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
import foo, bar as baz from 'lib'
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:13: error: unexpected identifier
|
|
|
|
import foo, bar as baz from 'lib'
|
|
|
|
^^^
|
|
|
|
'''
|
|
|
|
|
|
|
|
test "cannot export * without a module to export from", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
export *
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:9: error: unexpected end of input
|
|
|
|
export *
|
|
|
|
^
|
|
|
|
'''
|
|
|
|
|
|
|
|
test "imports and exports must be top-level", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
if foo
|
|
|
|
import { bar } from 'lib'
|
|
|
|
''', '''
|
|
|
|
[stdin]:2:3: error: import statements must be at top-level scope
|
|
|
|
import { bar } from 'lib'
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
foo = ->
|
|
|
|
export { bar }
|
|
|
|
''', '''
|
|
|
|
[stdin]:2:3: error: export statements must be at top-level scope
|
|
|
|
export { bar }
|
|
|
|
^^^^^^^^^^^^^^
|
|
|
|
'''
|
|
|
|
|
|
|
|
test "cannot import the same member more than once", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
import { foo, foo } from 'lib'
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:15: error: 'foo' has already been declared
|
|
|
|
import { foo, foo } from 'lib'
|
|
|
|
^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
import { foo, bar, foo } from 'lib'
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:20: error: 'foo' has already been declared
|
|
|
|
import { foo, bar, foo } from 'lib'
|
|
|
|
^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
import { foo, bar as foo } from 'lib'
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:15: error: 'foo' has already been declared
|
|
|
|
import { foo, bar as foo } from 'lib'
|
|
|
|
^^^^^^^^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
import foo, { foo } from 'lib'
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:15: error: 'foo' has already been declared
|
|
|
|
import foo, { foo } from 'lib'
|
|
|
|
^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
import foo, { bar as foo } from 'lib'
|
|
|
|
''', '''
|
|
|
|
[stdin]:1:15: error: 'foo' has already been declared
|
|
|
|
import foo, { bar as foo } from 'lib'
|
|
|
|
^^^^^^^^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
import foo from 'libA'
|
|
|
|
import foo from 'libB'
|
|
|
|
''', '''
|
|
|
|
[stdin]:2:8: error: 'foo' has already been declared
|
|
|
|
import foo from 'libB'
|
|
|
|
^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
import * as foo from 'libA'
|
|
|
|
import { foo } from 'libB'
|
|
|
|
''', '''
|
|
|
|
[stdin]:2:10: error: 'foo' has already been declared
|
|
|
|
import { foo } from 'libB'
|
|
|
|
^^^
|
|
|
|
'''
|
|
|
|
|
|
|
|
test "imported members cannot be reassigned", ->
|
|
|
|
assertErrorFormat '''
|
|
|
|
import { foo } from 'lib'
|
|
|
|
foo = 'bar'
|
|
|
|
''', '''
|
|
|
|
[stdin]:2:1: error: 'foo' is read-only
|
|
|
|
foo = 'bar'
|
|
|
|
^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
import { foo } from 'lib'
|
|
|
|
export default foo = 'bar'
|
|
|
|
''', '''
|
|
|
|
[stdin]:2:16: error: 'foo' is read-only
|
|
|
|
export default foo = 'bar'
|
|
|
|
^^^
|
|
|
|
'''
|
|
|
|
assertErrorFormat '''
|
|
|
|
import { foo } from 'lib'
|
|
|
|
export foo = 'bar'
|
|
|
|
''', '''
|
|
|
|
[stdin]:2:8: error: 'foo' is read-only
|
|
|
|
export foo = 'bar'
|
|
|
|
^^^
|
|
|
|
'''
|
[CS2] Output ES2015 arrow functions, default parameters, rest parameters (#4311)
* Eliminate wrapper around “bound” (arrow) functions; output `=>` for such functions
* Remove irrelevant (and breaking) tests
* Minor cleanup
* When a function parameter is a splat (i.e., it uses the ES2015 rest parameter syntax) output that parameter as ES2015
* Rearrange function parameters when one of the parameters is a splat and isn’t the last parameter (very WIP)
* Handle params like `@param`, adding assignment expressions for them when they appear; ensure splat parameter is last
* Add parameter names (not a text like `'\nValue IdentifierLiteral: a'`) to the scope, so that parameters can’t be deleted; move body-related lines together; more explanation of what’s going on
* For parameters with a default value, correctly add the parameter name to the function scope
* Handle expansions in function parameters: when an expansion is found, set the parameters to only be the original parameters left of the expansion, then an `...args` parameter; and in the function body define variables for the parameters to the right of the expansion, including setting default values
* Handle splat parameters the same way we handle expansions: if a splat parameter is found, it becomes the last parameter in the function definition, and all following parameters get declared in the function body. Fix the splat/rest parameter values after the post-splat parameters have been extracted from it. Clean up `Code.compileNode` so that we loop through the parameters only once, and we create all expressions using calls like `new IdentifierLiteral` rather than `@makeCode`.
* Fix parameter name when a parameter is a splat attached to `this` (e.g. `@param...`)
* Rather than assigning post-splat parameters based on index, use slice; passes test “Functions with splats being called with too few arguments”
* Dial back our w00t indentation
* Better parsing of parameter names (WIP)
* Refactor processing of splat/expansion parameters
* Fix assignment of default parameters for parameters that come after a splat
* Better check for whether a param is attached to `this`
* More understandable variable names
* For parameters after a splat or expansion, assign them similar to the 1.x destructuring method of using `arguments`, except only concern ourselves with the post-splat parameters instead of all parameters; and use the splat/expansion parameter name, since `arguments` in ES fat arrow functions refers to the parent function’s `arguments` rather than the fat arrow function’s arguments/parameters
* Don’t add unnamed parameters (like `[]` as a parameter) to the function scope
* Disallow multiple splat/expansion parameters in function definitions; disallow lone expansion parameters
* Fix `this` params not getting assigned if the parameter is after a splat parameter
* Allow names of function parameters attached to `this` to be reserved words
* Always add a statement to the function body defining a variable with its default value, if it has one, if the variable `== null`; this covers the case when ES doesn’t apply the default value when `null` is passed in as a value, but CoffeeScript expects `null` and `undefined` to act interchangeably
* Aftermath of having both `undefined` and `null` trigger the use of default values for parameters with default values
* More careful parsing of destructured parameters
* Fall back to processing destructured parameters in the function body, to account for `this` or default values within destructured objects
* Clean up comments
* Restore new bare function test, minus the arrow function part of it
* Test that bound/arrow functions aren’t overwriting the `arguments` object, which should refer to the parent scope’s `arguments` (like `this`)
* Follow ES2015 spec for parameter default values: `null` gets assigned as as `null`, not the default value
* Mimic ES default parameters behavior for parameters after a splat or expansion parameter
* Bound functions cannot be generators: remove no-longer-relevant test, add check to throw error if `yield` appears inside a bound (arrow) function
* Error for bound generator functions should underline the `yield`
2016-10-26 01:26:13 -04:00
|
|
|
|
|
|
|
test "bound functions cannot be generators", ->
|
|
|
|
assertErrorFormat 'f = => yield this', '''
|
|
|
|
[stdin]:1:8: error: yield cannot occur inside bound (fat arrow) functions
|
|
|
|
f = => yield this
|
|
|
|
^^^^^^^^^^
|
|
|
|
'''
|