jashkenas/coffee-script — pull request #2021 by geraldalewis (2012-01-09 18:33:17+00:00)
Title: Use Strict

I wanted to get the ball rolling on #1547 "CoffeeScript `use strict`".

This patch does not enable `strict` mode. However, it does enforce `strict` mode's "early errors". These are sensible constraints that most JS devs adhere to anyway. As anecdotal evidence, almost no existing CoffeeScript compiler code needed to be rewritten to conform to `strict mode`.

Each "early error" gets its own discrete patch. Most commits are only a line or two; this isn't as big a change as it may appear. This `pull` is in the early stages of development, and there are surely some edge cases to address and some code to clean up: my intention is to engender discussion on adopting what we can of `strict` mode.

The following are now considered errors. Links are provided to the relevant commit.

[**7.8.3** Numeric Literals](http://es5.github.com/#x7.8.3)

oct = 0121 # octals

Commit 6a44f2c1

[**B.1.2** String Literals](http://es5.github.com/#B.1.2)

octEscSeq = "\121" # octal escape sequences

Commit 3fb064f2

[**11.1.5** Object Initialiser](http://es5.github.com/#x11.1.5)

x: 1, x: 1 # duplicate prop names in object literal

Commit b74efbf9

[**11.4.1** The delete Operator](http://es5.github.com/#x11.4.1)

x = 1; delete x # delete var
delete undefined # delete undefined
(x)-> delete x # delete function argument

Commit 6bbc5ae7

[**13** Function Definition (13.1 Strict Mode Restrictions)](http://es5.github.com/#x13)

(x,x)-> # duplicate formal param

Commit 6c9ded83

[**7.6.1.2** Future Reserved Words](http://es5.github.com/#x7.6.1.2)

implements = 1 # assigning to future reserved keyword
interface = 1
let = 1
package = 1
private = 1
protected = 1
public = 1
static = 1
yield = 1

Commit 696d8734

**`eval` and `arguments` restrictions**

[**12.14** The try Statement (12.14.1 Strict Mode Restrictions)](http://es5.github.com/#x12.14)

try e catch eval # catch identifier eval
try e catch arguments # catch identifier arguments

[**13** Function Definition (13.1 Strict Mode Restrictions)](http://es5.github.com/#x13.1)

(eval)-> # identifier "eval" in formal params
(arguments)-> # identifier "arguments" in formal params
class eval # function declaration `function eval(){}`
class arguments # function declaration `function arguments(){}`

[**11.13.1** Simple Assignment](http://es5.github.com/#x11.13.1)

eval = 1 # assigning to eval
arguments = 1 # assigning to arguments

[**11.3.1** Postfix Increment Operator](http://es5.github.com/#x11.3.1)

eval++ # incrementing eval
arguments++ # incrementing arguments

Commit 423f54dc

- - - -

Tests a9cfd065

- - - -

Thanks!