Reserving __hasProp and friends, for safety's sake.
This commit is contained in:
parent
a322b3ad68
commit
96f076983e
|
@ -581,7 +581,7 @@
|
|||
JS_KEYWORDS = ["if", "else", "true", "false", "new", "return", "try", "catch", "finally", "throw", "break", "continue", "for", "in", "while", "delete", "instanceof", "typeof", "switch", "super", "extends", "class", "this", "null"];
|
||||
COFFEE_ALIASES = ["and", "or", "is", "isnt", "not"];
|
||||
COFFEE_KEYWORDS = COFFEE_ALIASES.concat(["then", "unless", "until", "loop", "yes", "no", "on", "off", "of", "by", "where", "when"]);
|
||||
RESERVED = ["case", "default", "do", "function", "var", "void", "with", "const", "let", "enum", "export", "import", "native"];
|
||||
RESERVED = ["case", "default", "do", "function", "var", "void", "with", "const", "let", "enum", "export", "import", "native", "__hasProp", "__extends", "__slice"];
|
||||
JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED);
|
||||
IDENTIFIER = /^([a-zA-Z\$_](\w|\$)*)/;
|
||||
NUMBER = /^(((\b0(x|X)[0-9a-fA-F]+)|((\b[0-9]+(\.[0-9]+)?|\.[0-9]+)(e[+\-]?[0-9]+)?)))\b/i;
|
||||
|
|
|
@ -1647,9 +1647,9 @@
|
|||
}
|
||||
});
|
||||
UTILITIES = {
|
||||
__extends: "function(child, parent) {\n var ctor = function(){ };\n ctor.prototype = parent.prototype;\n child.__superClass__ = parent.prototype;\n child.prototype = new ctor();\n child.prototype.constructor = child;\n }",
|
||||
__hasProp: 'Object.prototype.hasOwnProperty',
|
||||
__slice: 'Array.prototype.slice'
|
||||
'extends': "function(child, parent) {\n var ctor = function(){ };\n ctor.prototype = parent.prototype;\n child.__superClass__ = parent.prototype;\n child.prototype = new ctor();\n child.prototype.constructor = child;\n }",
|
||||
hasProp: 'Object.prototype.hasOwnProperty',
|
||||
slice: 'Array.prototype.slice'
|
||||
};
|
||||
TAB = ' ';
|
||||
TRAILING_WHITESPACE = /[ \t]+$/gm;
|
||||
|
@ -1663,7 +1663,7 @@
|
|||
utility = function(name) {
|
||||
var ref;
|
||||
ref = ("__" + name);
|
||||
Scope.root.assign(ref, UTILITIES[ref]);
|
||||
Scope.root.assign(ref, UTILITIES[name]);
|
||||
return ref;
|
||||
};
|
||||
})();
|
||||
|
|
|
@ -501,8 +501,9 @@ COFFEE_KEYWORDS: COFFEE_ALIASES.concat [
|
|||
# used by CoffeeScript internally. We throw an error when these are encountered,
|
||||
# to avoid having a JavaScript error at runtime.
|
||||
RESERVED: [
|
||||
"case", "default", "do", "function", "var", "void", "with"
|
||||
"const", "let", "enum", "export", "import", "native"
|
||||
"case", "default", "do", "function", "var", "void", "with",
|
||||
"const", "let", "enum", "export", "import", "native",
|
||||
"__hasProp", "__extends", "__slice"
|
||||
]
|
||||
|
||||
# The superset of both JavaScript keywords and reserved words, none of which may
|
||||
|
|
|
@ -1460,19 +1460,19 @@ UTILITIES: {
|
|||
# Correctly set up a prototype chain for inheritance, including a reference
|
||||
# to the superclass for `super()` calls. See:
|
||||
# [goog.inherits](http://closure-library.googlecode.com/svn/docs/closureGoogBase.js.source.html#line1206).
|
||||
__extends: """
|
||||
function(child, parent) {
|
||||
var ctor = function(){ };
|
||||
ctor.prototype = parent.prototype;
|
||||
child.__superClass__ = parent.prototype;
|
||||
child.prototype = new ctor();
|
||||
child.prototype.constructor = child;
|
||||
}
|
||||
"""
|
||||
extends: """
|
||||
function(child, parent) {
|
||||
var ctor = function(){ };
|
||||
ctor.prototype = parent.prototype;
|
||||
child.__superClass__ = parent.prototype;
|
||||
child.prototype = new ctor();
|
||||
child.prototype.constructor = child;
|
||||
}
|
||||
"""
|
||||
|
||||
# Shortcuts to speed up the lookup time for native functions.
|
||||
__hasProp: 'Object.prototype.hasOwnProperty'
|
||||
__slice: 'Array.prototype.slice'
|
||||
hasProp: 'Object.prototype.hasOwnProperty'
|
||||
slice: 'Array.prototype.slice'
|
||||
|
||||
}
|
||||
|
||||
|
@ -1506,5 +1506,5 @@ literal: (name) ->
|
|||
# Helper for ensuring that utility functions are assigned at the top level.
|
||||
utility: (name) ->
|
||||
ref: "__$name"
|
||||
Scope.root.assign ref, UTILITIES[ref]
|
||||
Scope.root.assign ref, UTILITIES[name]
|
||||
ref
|
||||
|
|
Loading…
Reference in New Issue