Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed some corner-case name crashes

  • Loading branch information...
commit ee292f658667014d4f3cb36d77d1829258fdd4b0 1 parent 69b4e5d
@satyr authored
Showing with 22 additions and 4 deletions.
  1. +9 −2 lib/ast.js
  2. +8 −2 src/ast.co
  3. +5 −0 test/assignment.co
View
11 lib/ast.js
@@ -2350,7 +2350,7 @@ exports.Class = Class = (function(superclass){
continue;
}
if (key.isComplex()) {
- key = Var(o.scope.temporary('key'));
+ key = Var(o.scope.temporary('method'));
prop.key = Assign(key, prop.key);
}
for (j$ = 0, len2$ = (ref1$ = [].concat(prop.val)).length; j$ < len2$; ++j$) {
@@ -3412,7 +3412,7 @@ ref$.assign = function(name, value){
};
ref$.temporary = function(name){
name || (name = 'ref');
- while (this.variables[name + "$."]) {
+ while (this.checkTemporary(name)) {
name = name.length < 2 && name < 'z'
? String.fromCharCode(name.charCodeAt() + 1)
: name.replace(/\d*$/, fn$);
@@ -3434,6 +3434,13 @@ ref$.check = function(name, above){
}
return (ref$ = this.parent) != null ? ref$.check(name, above) : void 8;
};
+ref$.checkTemporary = function(name){
+ var type, ref$;
+ if ((type = this.variables[name + "$."]) || !this.shared) {
+ return type;
+ }
+ return (ref$ = this.parent) != null ? ref$.checkTemporary(name) : void 8;
+};
ref$.checkReadOnly = function(name){
var that, ref$, key$;
if (that = this.READ_ONLY[this.check(name, true)]) {
View
10 src/ast.co
@@ -1456,7 +1456,7 @@ class exports.Class extends Node
for {key}:prop of node.items
continue unless prop.val instanceof Fun or prop.accessor
if key.isComplex!
- key = Var o.scope.temporary \key
+ key = Var o.scope.temporary \method
prop.key = Assign key, prop.key
for []concat prop.val
&meth = key
@@ -2123,7 +2123,7 @@ Scope::<<<
# If we need to store an intermediate result, find an available name for a
# compiler-generated variable. `var$`, `var1$`, and so on.
temporary: (name || \ref) ->
- while @variables"#name\$."
+ while @checkTemporary name
name = if name.length < 2 and name < \z
then String.fromCharCode name.charCodeAt! + 1
else name.replace /\d*$/ -> ++it
@@ -2140,6 +2140,12 @@ Scope::<<<
return type if (type = @variables"#name.") or not above
@parent?check name, above
+ # Checks to see if a temporary variable has already been declared
+ # in the nearest non-wrapper scope.
+ checkTemporary: (name) ->
+ return type if (type = @variables"#name\$.") or not @shared
+ @parent?checkTemporary name
+
# Checks if a variable can be reassigned.
checkReadOnly: (name) ->
return that if @READ_ONLY[@check name, true]
View
5 test/assignment.co
@@ -369,5 +369,10 @@ o = p: q: \r
o.p[String \q].=replace /^|$/g "<#<>>"
eq o.p.q, '<r>r<r>'
+let
+ eq o.p, o[String \p] = try
+ o[String \q] = <>
+ <>
+
for ['<>' '[a] = <>' 'f = -> <>' '[<>] * 2']
compileThrows 'stray <>' 1 &
Please sign in to comment.
Something went wrong with that request. Please try again.