Skip to content
This repository
Browse code

fixes #2052: don't manually assign constructors' `name` property

I'm not sure how we would test this, so... no tests.
  • Loading branch information...
commit f3a1f466793ede9da1fe164111d482831392270c 1 parent 0867326
Michael Ficarra authored April 11, 2012
2  lib/coffee-script/lexer.js
@@ -9,8 +9,6 @@
9 9
 
10 10
   exports.Lexer = Lexer = (function() {
11 11
 
12  
-    Lexer.name = 'Lexer';
13  
-
14 12
     function Lexer() {}
15 13
 
16 14
     Lexer.prototype.tokenize = function(code, opts) {
61  lib/coffee-script/nodes.js
@@ -32,8 +32,6 @@
32 32
 
33 33
   exports.Base = Base = (function() {
34 34
 
35  
-    Base.name = 'Base';
36  
-
37 35
     function Base() {}
38 36
 
39 37
     Base.prototype.compile = function(o, lvl) {
@@ -210,8 +208,6 @@
210 208
 
211 209
     __extends(Block, _super);
212 210
 
213  
-    Block.name = 'Block';
214  
-
215 211
     function Block(nodes) {
216 212
       this.expressions = compact(flatten(nodes || []));
217 213
     }
@@ -432,8 +428,6 @@
432 428
 
433 429
     __extends(Literal, _super);
434 430
 
435  
-    Literal.name = 'Literal';
436  
-
437 431
     function Literal(value) {
438 432
       this.value = value;
439 433
     }
@@ -492,8 +486,6 @@
492 486
 
493 487
     __extends(Return, _super);
494 488
 
495  
-    Return.name = 'Return';
496  
-
497 489
     function Return(expr) {
498 490
       if (expr && !expr.unwrap().isUndefined) {
499 491
         this.expression = expr;
@@ -530,8 +522,6 @@
530 522
 
531 523
     __extends(Value, _super);
532 524
 
533  
-    Value.name = 'Value';
534  
-
535 525
     function Value(base, props, tag) {
536 526
       if (!props && base instanceof Value) {
537 527
         return base;
@@ -698,8 +688,6 @@
698 688
 
699 689
     __extends(Comment, _super);
700 690
 
701  
-    Comment.name = 'Comment';
702  
-
703 691
     function Comment(comment) {
704 692
       this.comment = comment;
705 693
     }
@@ -725,8 +713,6 @@
725 713
 
726 714
     __extends(Call, _super);
727 715
 
728  
-    Call.name = 'Call';
729  
-
730 716
     function Call(variable, args, soak) {
731 717
       this.args = args != null ? args : [];
732 718
       this.soak = soak;
@@ -912,8 +898,6 @@
912 898
 
913 899
     __extends(Extends, _super);
914 900
 
915  
-    Extends.name = 'Extends';
916  
-
917 901
     function Extends(child, parent) {
918 902
       this.child = child;
919 903
       this.parent = parent;
@@ -933,8 +917,6 @@
933 917
 
934 918
     __extends(Access, _super);
935 919
 
936  
-    Access.name = 'Access';
937  
-
938 920
     function Access(name, tag) {
939 921
       this.name = name;
940 922
       this.name.asKey = true;
@@ -963,8 +945,6 @@
963 945
 
964 946
     __extends(Index, _super);
965 947
 
966  
-    Index.name = 'Index';
967  
-
968 948
     function Index(index) {
969 949
       this.index = index;
970 950
     }
@@ -987,8 +967,6 @@
987 967
 
988 968
     __extends(Range, _super);
989 969
 
990  
-    Range.name = 'Range';
991  
-
992 970
     Range.prototype.children = ['from', 'to'];
993 971
 
994 972
     function Range(from, to, tag) {
@@ -1090,8 +1068,6 @@
1090 1068
 
1091 1069
     __extends(Slice, _super);
1092 1070
 
1093  
-    Slice.name = 'Slice';
1094  
-
1095 1071
     Slice.prototype.children = ['range'];
1096 1072
 
1097 1073
     function Slice(range) {
@@ -1118,8 +1094,6 @@
1118 1094
 
1119 1095
     __extends(Obj, _super);
1120 1096
 
1121  
-    Obj.name = 'Obj';
1122  
-
1123 1097
     function Obj(props, generated) {
1124 1098
       this.generated = generated != null ? generated : false;
1125 1099
       this.objects = this.properties = props || [];
@@ -1207,8 +1181,6 @@
1207 1181
 
1208 1182
     __extends(Arr, _super);
1209 1183
 
1210  
-    Arr.name = 'Arr';
1211  
-
1212 1184
     function Arr(objs) {
1213 1185
       this.objects = objs || [];
1214 1186
     }
@@ -1263,8 +1235,6 @@
1263 1235
 
1264 1236
     __extends(Class, _super);
1265 1237
 
1266  
-    Class.name = 'Class';
1267  
-
1268 1238
     function Class(variable, parent, body) {
1269 1239
       this.variable = variable;
1270 1240
       this.parent = parent;
@@ -1426,9 +1396,6 @@
1426 1396
       if (!(this.ctor instanceof Code)) {
1427 1397
         this.body.expressions.unshift(this.ctor);
1428 1398
       }
1429  
-      if (decl) {
1430  
-        this.body.expressions.unshift(new Assign(new Value(new Literal(name), [new Access(new Literal('name'))]), new Literal("'" + name + "'")));
1431  
-      }
1432 1399
       this.body.expressions.push(lname);
1433 1400
       (_ref2 = this.body.expressions).unshift.apply(_ref2, this.directives);
1434 1401
       this.addBoundFunctions(o);
@@ -1455,8 +1422,6 @@
1455 1422
 
1456 1423
     __extends(Assign, _super);
1457 1424
 
1458  
-    Assign.name = 'Assign';
1459  
-
1460 1425
     function Assign(variable, value, context, options) {
1461 1426
       var forbidden, name, _ref2;
1462 1427
       this.variable = variable;
@@ -1677,8 +1642,6 @@
1677 1642
 
1678 1643
     __extends(Code, _super);
1679 1644
 
1680  
-    Code.name = 'Code';
1681  
-
1682 1645
     function Code(params, body, tag) {
1683 1646
       this.params = params || [];
1684 1647
       this.body = body || new Block;
@@ -1835,8 +1798,6 @@
1835 1798
 
1836 1799
     __extends(Param, _super);
1837 1800
 
1838  
-    Param.name = 'Param';
1839  
-
1840 1801
     function Param(name, value, splat) {
1841 1802
       var _ref2;
1842 1803
       this.name = name;
@@ -1923,8 +1884,6 @@
1923 1884
 
1924 1885
     __extends(Splat, _super);
1925 1886
 
1926  
-    Splat.name = 'Splat';
1927  
-
1928 1887
     Splat.prototype.children = ['name'];
1929 1888
 
1930 1889
     Splat.prototype.isAssignable = YES;
@@ -1995,8 +1954,6 @@
1995 1954
 
1996 1955
     __extends(While, _super);
1997 1956
 
1998  
-    While.name = 'While';
1999  
-
2000 1957
     function While(condition, options) {
2001 1958
       this.condition = (options != null ? options.invert : void 0) ? condition.invert() : condition;
2002 1959
       this.guard = options != null ? options.guard : void 0;
@@ -2078,8 +2035,6 @@
2078 2035
 
2079 2036
     __extends(Op, _super);
2080 2037
 
2081  
-    Op.name = 'Op';
2082  
-
2083 2038
     function Op(op, first, second, flip) {
2084 2039
       if (op === 'in') {
2085 2040
         return new In(first, second);
@@ -2272,8 +2227,6 @@
2272 2227
 
2273 2228
     __extends(In, _super);
2274 2229
 
2275  
-    In.name = 'In';
2276  
-
2277 2230
     function In(object, array) {
2278 2231
       this.object = object;
2279 2232
       this.array = array;
@@ -2354,8 +2307,6 @@
2354 2307
 
2355 2308
     __extends(Try, _super);
2356 2309
 
2357  
-    Try.name = 'Try';
2358  
-
2359 2310
     function Try(attempt, error, recovery, ensure) {
2360 2311
       this.attempt = attempt;
2361 2312
       this.error = error;
@@ -2413,8 +2364,6 @@
2413 2364
 
2414 2365
     __extends(Throw, _super);
2415 2366
 
2416  
-    Throw.name = 'Throw';
2417  
-
2418 2367
     function Throw(expression) {
2419 2368
       this.expression = expression;
2420 2369
     }
@@ -2439,8 +2388,6 @@
2439 2388
 
2440 2389
     __extends(Existence, _super);
2441 2390
 
2442  
-    Existence.name = 'Existence';
2443  
-
2444 2391
     function Existence(expression) {
2445 2392
       this.expression = expression;
2446 2393
     }
@@ -2474,8 +2421,6 @@
2474 2421
 
2475 2422
     __extends(Parens, _super);
2476 2423
 
2477  
-    Parens.name = 'Parens';
2478  
-
2479 2424
     function Parens(body) {
2480 2425
       this.body = body;
2481 2426
     }
@@ -2514,8 +2459,6 @@
2514 2459
 
2515 2460
     __extends(For, _super);
2516 2461
 
2517  
-    For.name = 'For';
2518  
-
2519 2462
     function For(body, source) {
2520 2463
       var _ref2;
2521 2464
       this.source = source.source, this.guard = source.guard, this.step = source.step, this.name = source.name, this.index = source.index;
@@ -2673,8 +2616,6 @@
2673 2616
 
2674 2617
     __extends(Switch, _super);
2675 2618
 
2676  
-    Switch.name = 'Switch';
2677  
-
2678 2619
     function Switch(subject, cases, otherwise) {
2679 2620
       this.subject = subject;
2680 2621
       this.cases = cases;
@@ -2760,8 +2701,6 @@
2760 2701
 
2761 2702
     __extends(If, _super);
2762 2703
 
2763  
-    If.name = 'If';
2764  
-
2765 2704
     function If(condition, body, options) {
2766 2705
       this.body = body;
2767 2706
       if (options == null) {
2  lib/coffee-script/optparse.js
@@ -4,8 +4,6 @@
4 4
 
5 5
   exports.OptionParser = OptionParser = (function() {
6 6
 
7  
-    OptionParser.name = 'OptionParser';
8  
-
9 7
     function OptionParser(rules, banner) {
10 8
       this.banner = banner;
11 9
       this.rules = buildRules(rules);
2  lib/coffee-script/rewriter.js
@@ -6,8 +6,6 @@
6 6
 
7 7
   exports.Rewriter = (function() {
8 8
 
9  
-    Rewriter.name = 'Rewriter';
10  
-
11 9
     function Rewriter() {}
12 10
 
13 11
     Rewriter.prototype.rewrite = function(tokens) {
2  lib/coffee-script/scope.js
@@ -6,8 +6,6 @@
6 6
 
7 7
   exports.Scope = Scope = (function() {
8 8
 
9  
-    Scope.name = 'Scope';
10  
-
11 9
     Scope.root = null;
12 10
 
13 11
     function Scope(parent, expressions, method) {
2  src/nodes.coffee
@@ -966,8 +966,6 @@ exports.Class = class Class extends Base
966 966
     @ensureConstructor name
967 967
     @body.spaced = yes
968 968
     @body.expressions.unshift @ctor unless @ctor instanceof Code
969  
-    if decl
970  
-      @body.expressions.unshift new Assign (new Value (new Literal name), [new Access new Literal 'name']), (new Literal "'#{name}'")
971 969
     @body.expressions.push lname
972 970
     @body.expressions.unshift @directives...
973 971
     @addBoundFunctions o

2 notes on commit f3a1f46

Paul Miller
try
  do ->
    'use strict'
    class Test
  ok yes
catch error
  ok no

We should probably revert the test also.

Michael Ficarra
Collaborator

Ah, of course. Thanks.

edit: Unfortunately, that assignment doesn't throw a TypeError in node, even though [[Writable]] is false.

> Object.getOwnPropertyDescriptor(function(){}, 'name')
{ value: '',
  writable: false,
  enumerable: false,
  configurable: false }

But at least we'll catch the error if our classes ever cause a strict mode problem in a conforming interpreter.

edit: 4043124

Please sign in to comment.
Something went wrong with that request. Please try again.