Skip to content

Commit

Permalink
correcting broken fix for #2333 regarding string escape sequences
Browse files Browse the repository at this point in the history
Sorry for all the commits! It should really be done this time.
  • Loading branch information
michaelficarra committed May 16, 2012
1 parent da22989 commit 29b9c3b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 17 deletions.
40 changes: 29 additions & 11 deletions lib/coffee-script/nodes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions src/nodes.coffee
Expand Up @@ -802,20 +802,25 @@ exports.Obj = class Obj extends Base
compileNode: (o) ->
props = @properties
propNames = []
normalise = (s) -> switch s[0]
when '"' then s[1...-1].replace /\\"/g, '"'
when "'" then s[1...-1].replace /\\'/g, "'"
normaliseString = (s) ->
quoteNormalised = switch s[0]
when '"' then s[1...-1].replace /\\"/g, '"'
when "'" then s[1...-1].replace /\\'/g, "'"
octalNormalised = quoteNormalised.replace /\\([0btnvfr\\])/, (match, c) ->
{0:"\0", b:"\b", t:"\t", n:"\n", v:"\v", f:"\f", r:"\r", "\\":"\\"}[c]
octalNormalised.replace /\\x([0-9a-f]{2})|\\u([0-9a-f]{4})/i, (match, h, u) ->
String.fromCharCode parseInt (h ? u), 16
isDuplicate = (x) ->
mx = x.match /^['"]/
(y) ->
return true if y is x or +y is +x
my = y.match /^['"]/
if mx and my
return true if normalise(x) is normalise y
return true if normaliseString(x) is normaliseString y
else if mx
return true if y is x[1...-1]
return true if y is normaliseString x
else if my
return true if x is y[1...-1]
return true if x is normaliseString y
false
for prop in @properties
prop = prop.variable if prop.isComplex()
Expand Down
4 changes: 4 additions & 0 deletions test/strict.coffee
Expand Up @@ -70,7 +70,11 @@ test "#2333: more duplicate property prohibitions", ->
strict '{.1:0, 1e-1:0}'
strict '{100:0, 1e2:0}'
strict '{"\\0":0, "\\x00":0}'
strict '{"\\n":0, "\\x0A":0}'
strict '{"\\\\":0, "\\x5c":0}'
strict 'a = 0; {a, "a":0}'
strict "{'\\'a':0, \"'a\":0}"
strict "{'\\\\a':0, '\\\\a':0}"
strictOk '{0:0, "0x0":0}'
strictOk '{"a":0, "\'a\'":0}'

Expand Down

2 comments on commit 29b9c3b

@michaelficarra
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably be DRYed up a ton by reusing some lexer code, but this works fine for now.

@satyr
Copy link
Collaborator

@satyr satyr commented on 29b9c3b May 16, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ bin/coffee -s
'use strict'
{'
0', 0}
^D
.:8
    0: 0
    ^
SyntaxError: Duplicate data property in object literal not allowed in strict mode
...

Please sign in to comment.