mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
We no longer need to wrap in quotes JavaScript reserved words used as properties (#4527)
This commit is contained in:
parent
5651b8b14b
commit
7e35c2c3da
9 changed files with 41 additions and 54 deletions
|
@ -926,7 +926,7 @@
|
|||
|
||||
looksStatic(className) {
|
||||
var ref1;
|
||||
return (this["this"] || this.base instanceof ThisLiteral || this.base.value === className) && this.properties.length === 1 && ((ref1 = this.properties[0].name) != null ? ref1.value : void 0) !== 'prototype';
|
||||
return (this.this || this.base instanceof ThisLiteral || this.base.value === className) && this.properties.length === 1 && ((ref1 = this.properties[0].name) != null ? ref1.value : void 0) !== 'prototype';
|
||||
}
|
||||
|
||||
unwrap() {
|
||||
|
@ -1289,15 +1289,11 @@
|
|||
}
|
||||
|
||||
compileToFragments(o) {
|
||||
var name, node, ref1;
|
||||
var name, node;
|
||||
name = this.name.compileToFragments(o);
|
||||
node = this.name.unwrap();
|
||||
if (node instanceof PropertyName) {
|
||||
if (ref1 = node.value, indexOf.call(JS_FORBIDDEN, ref1) >= 0) {
|
||||
return [this.makeCode('["'), ...name, this.makeCode('"]')];
|
||||
} else {
|
||||
return [this.makeCode('.'), ...name];
|
||||
}
|
||||
return [this.makeCode('.'), ...name];
|
||||
} else {
|
||||
return [this.makeCode('['), ...name, this.makeCode(']')];
|
||||
}
|
||||
|
@ -1529,7 +1525,7 @@
|
|||
indent = isCompact || prop instanceof Comment ? '' : idt;
|
||||
key = prop instanceof Assign && prop.context === 'object' ? prop.variable : prop instanceof Assign ? (!this.lhs ? prop.operatorToken.error(`unexpected ${prop.operatorToken.value}`) : void 0, prop.variable) : !(prop instanceof Comment) ? prop : void 0;
|
||||
if (key instanceof Value && key.hasProperties()) {
|
||||
if (prop.context === 'object' || !key["this"]) {
|
||||
if (prop.context === 'object' || !key.this) {
|
||||
key.error('invalid object key');
|
||||
}
|
||||
key = key.properties[0].name;
|
||||
|
@ -1965,7 +1961,7 @@
|
|||
class ExecutableClassBody extends Base {
|
||||
constructor(_class, body1 = new Block) {
|
||||
super();
|
||||
this["class"] = _class;
|
||||
this.class = _class;
|
||||
this.body = body1;
|
||||
}
|
||||
|
||||
|
@ -1977,7 +1973,7 @@
|
|||
if (argumentsNode = this.body.contains(isLiteralArguments)) {
|
||||
argumentsNode.error("Class bodies shouldn't reference arguments");
|
||||
}
|
||||
this.name = (ref1 = this["class"].name) != null ? ref1 : this.defaultClassVariableName;
|
||||
this.name = (ref1 = this.class.name) != null ? ref1 : this.defaultClassVariableName;
|
||||
directives = this.walkBody();
|
||||
this.setContext();
|
||||
ident = new IdentifierLiteral(this.name);
|
||||
|
@ -1987,23 +1983,23 @@
|
|||
klass = new Parens(new Call(wrapper, args));
|
||||
this.body.spaced = true;
|
||||
o.classScope = wrapper.makeScope(o.scope);
|
||||
if (this["class"].hasNameClash) {
|
||||
if (this.class.hasNameClash) {
|
||||
parent = new IdentifierLiteral(o.classScope.freeVariable('superClass'));
|
||||
wrapper.params.push(new Param(parent));
|
||||
args.push(this["class"].parent);
|
||||
this["class"].parent = parent;
|
||||
args.push(this.class.parent);
|
||||
this.class.parent = parent;
|
||||
}
|
||||
if (this.externalCtor) {
|
||||
externalCtor = new IdentifierLiteral(o.classScope.freeVariable('ctor', {
|
||||
reserve: false
|
||||
}));
|
||||
this["class"].externalCtor = externalCtor;
|
||||
this.class.externalCtor = externalCtor;
|
||||
this.externalCtor.variable.base = externalCtor;
|
||||
}
|
||||
if (this.name !== this["class"].name) {
|
||||
this.body.expressions.unshift(new Assign(new IdentifierLiteral(this.name), this["class"]));
|
||||
if (this.name !== this.class.name) {
|
||||
this.body.expressions.unshift(new Assign(new IdentifierLiteral(this.name), this.class));
|
||||
} else {
|
||||
this.body.expressions.unshift(this["class"]);
|
||||
this.body.expressions.unshift(this.class);
|
||||
}
|
||||
this.body.expressions.unshift(...directives);
|
||||
this.body.push(ident);
|
||||
|
@ -2076,7 +2072,7 @@
|
|||
base.error('constructors must be defined at the top level of a class body');
|
||||
}
|
||||
assign = this.externalCtor = new Assign(new Value, value);
|
||||
} else if (!assign.variable["this"]) {
|
||||
} else if (!assign.variable.this) {
|
||||
name = new (base.shouldCache() ? Index : Access)(base);
|
||||
prototype = new Access(new PropertyName('prototype'));
|
||||
variable = new Value(new ThisLiteral(), [prototype, name]);
|
||||
|
@ -2360,7 +2356,7 @@
|
|||
}
|
||||
|
||||
compileNode(o) {
|
||||
var answer, compiledName, isValue, j, name, properties, prototype, ref1, ref2, ref3, ref4, ref5, ref6, val, varBase;
|
||||
var answer, compiledName, isValue, j, name, properties, prototype, ref1, ref2, ref3, ref4, ref5, val, varBase;
|
||||
isValue = this.variable instanceof Value;
|
||||
if (isValue) {
|
||||
this.variable.param = this.param;
|
||||
|
@ -2418,9 +2414,6 @@
|
|||
if (this.variable.shouldCache()) {
|
||||
compiledName.unshift(this.makeCode('['));
|
||||
compiledName.push(this.makeCode(']'));
|
||||
} else if (ref6 = fragmentsToText(compiledName), indexOf.call(JS_FORBIDDEN, ref6) >= 0) {
|
||||
compiledName.unshift(this.makeCode('"'));
|
||||
compiledName.push(this.makeCode('"'));
|
||||
}
|
||||
return compiledName.concat(this.makeCode(": "), val);
|
||||
}
|
||||
|
@ -2469,7 +2462,7 @@
|
|||
defaultValue = obj.value;
|
||||
obj = obj.variable;
|
||||
}
|
||||
idx = isObject ? obj["this"] ? obj.properties[0].name : new PropertyName(obj.unwrap().value) : new NumberLiteral(0);
|
||||
idx = isObject ? obj.this ? obj.properties[0].name : new PropertyName(obj.unwrap().value) : new NumberLiteral(0);
|
||||
}
|
||||
acc = idx.unwrap() instanceof PropertyName;
|
||||
value = new Value(value);
|
||||
|
@ -2550,7 +2543,7 @@
|
|||
defaultValue = obj.value;
|
||||
obj = obj.variable;
|
||||
}
|
||||
idx = isObject ? obj["this"] ? obj.properties[0].name : new PropertyName(obj.unwrap().value) : new Literal(expandedIdx || idx);
|
||||
idx = isObject ? obj.this ? obj.properties[0].name : new PropertyName(obj.unwrap().value) : new Literal(expandedIdx || idx);
|
||||
}
|
||||
name = obj.unwrap().value;
|
||||
acc = idx.unwrap() instanceof PropertyName;
|
||||
|
@ -2725,7 +2718,7 @@
|
|||
node.error(`multiple parameters named '${name}'`);
|
||||
}
|
||||
paramNames.push(name);
|
||||
if (node["this"]) {
|
||||
if (node.this) {
|
||||
name = node.properties[0].name.value;
|
||||
if (indexOf.call(JS_FORBIDDEN, name) >= 0) {
|
||||
name = `_${name}`;
|
||||
|
@ -3006,7 +2999,7 @@
|
|||
return this.reference;
|
||||
}
|
||||
node = this.name;
|
||||
if (node["this"]) {
|
||||
if (node.this) {
|
||||
name = node.properties[0].name.value;
|
||||
if (indexOf.call(JS_FORBIDDEN, name) >= 0) {
|
||||
name = `_${name}`;
|
||||
|
@ -3052,7 +3045,7 @@
|
|||
} else if (obj instanceof Value) {
|
||||
if (obj.isArray() || obj.isObject()) {
|
||||
this.eachName(iterator, obj.base);
|
||||
} else if (obj["this"]) {
|
||||
} else if (obj.this) {
|
||||
atParam(obj);
|
||||
} else {
|
||||
iterator(obj.base.value, obj.base, this);
|
||||
|
@ -3072,7 +3065,7 @@
|
|||
var key;
|
||||
if (parent instanceof Obj) {
|
||||
key = node;
|
||||
if (node["this"]) {
|
||||
if (node.this) {
|
||||
key = node.properties[0].name;
|
||||
}
|
||||
return new Assign(new Value(key), newNode, 'object');
|
||||
|
@ -3235,10 +3228,10 @@
|
|||
return Op.prototype.generateDo(first);
|
||||
}
|
||||
if (op === 'new') {
|
||||
if (first instanceof Call && !first["do"] && !first.isNew) {
|
||||
if (first instanceof Call && !first.do && !first.isNew) {
|
||||
return first.newInstance();
|
||||
}
|
||||
if (first instanceof Code && first.bound || first["do"]) {
|
||||
if (first instanceof Code && first.bound || first.do) {
|
||||
first = new Parens(first);
|
||||
}
|
||||
}
|
||||
|
@ -3331,7 +3324,7 @@
|
|||
}
|
||||
}
|
||||
call = new Call(exp, passedParams);
|
||||
call["do"] = true;
|
||||
call.do = true;
|
||||
return call;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue