1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

Set the context of executable class body wrappers (#4828)

Fixes #4827.
This commit is contained in:
Chris Connelly 2017-12-18 18:51:08 +00:00 committed by Geoffrey Booth
parent 926cb8463c
commit ffbe51e374
6 changed files with 58 additions and 48 deletions

View file

@ -543,7 +543,7 @@
return Base; return Base;
})(); }).call(this);
//### HoistTarget //### HoistTarget
@ -997,7 +997,7 @@
return Block; return Block;
})(); }).call(this);
//### Literal //### Literal
@ -1030,7 +1030,7 @@
return Literal; return Literal;
})(); }).call(this);
exports.NumberLiteral = NumberLiteral = class NumberLiteral extends Literal {}; exports.NumberLiteral = NumberLiteral = class NumberLiteral extends Literal {};
@ -1094,7 +1094,7 @@
return IdentifierLiteral; return IdentifierLiteral;
})(); }).call(this);
exports.CSXTag = CSXTag = class CSXTag extends IdentifierLiteral {}; exports.CSXTag = CSXTag = class CSXTag extends IdentifierLiteral {};
@ -1105,7 +1105,7 @@
return PropertyName; return PropertyName;
})(); }).call(this);
exports.ComputedPropertyName = ComputedPropertyName = class ComputedPropertyName extends PropertyName { exports.ComputedPropertyName = ComputedPropertyName = class ComputedPropertyName extends PropertyName {
compileNode(o) { compileNode(o) {
@ -1137,7 +1137,7 @@
return StatementLiteral; return StatementLiteral;
})(); }).call(this);
exports.ThisLiteral = ThisLiteral = class ThisLiteral extends Literal { exports.ThisLiteral = ThisLiteral = class ThisLiteral extends Literal {
constructor() { constructor() {
@ -1231,7 +1231,7 @@
return Return; return Return;
})(); }).call(this);
// `yield return` works exactly like `return`, except that it turns the function // `yield return` works exactly like `return`, except that it turns the function
// into a generator. // into a generator.
@ -1490,7 +1490,7 @@
return Value; return Value;
})(); }).call(this);
//### HereComment //### HereComment
@ -1751,7 +1751,7 @@
return Call; return Call;
})(); }).call(this);
//### Super //### Super
@ -1789,7 +1789,7 @@
return SuperCall; return SuperCall;
})(); }).call(this);
exports.Super = Super = (function() { exports.Super = Super = (function() {
class Super extends Base { class Super extends Base {
@ -1837,7 +1837,7 @@
return Super; return Super;
})(); }).call(this);
//### RegexWithInterpolations //### RegexWithInterpolations
@ -1889,7 +1889,7 @@
return Extends; return Extends;
})(); }).call(this);
//### Access //### Access
@ -1922,7 +1922,7 @@
return Access; return Access;
})(); }).call(this);
//### Index //### Index
@ -1948,7 +1948,7 @@
return Index; return Index;
})(); }).call(this);
//### Range //### Range
@ -2065,7 +2065,7 @@
return Range; return Range;
})(); }).call(this);
//### Slice //### Slice
@ -2103,7 +2103,7 @@
return Slice; return Slice;
})(); }).call(this);
//### Obj //### Obj
@ -2348,7 +2348,7 @@
return Obj; return Obj;
})(); }).call(this);
//### Arr //### Arr
@ -2517,7 +2517,7 @@
return Arr; return Arr;
})(); }).call(this);
//### Class //### Class
@ -2803,7 +2803,7 @@
return Class; return Class;
})(); }).call(this);
exports.ExecutableClassBody = ExecutableClassBody = (function() { exports.ExecutableClassBody = ExecutableClassBody = (function() {
class ExecutableClassBody extends Base { class ExecutableClassBody extends Base {
@ -2826,9 +2826,9 @@
this.setContext(); this.setContext();
ident = new IdentifierLiteral(this.name); ident = new IdentifierLiteral(this.name);
params = []; params = [];
args = []; args = [new ThisLiteral];
wrapper = new Code(params, this.body); wrapper = new Code(params, this.body);
klass = new Parens(new Call(wrapper, args)); klass = new Parens(new Call(new Value(wrapper, [new Access(new PropertyName('call'))]), args));
this.body.spaced = true; this.body.spaced = true;
o.classScope = wrapper.makeScope(o.scope); o.classScope = wrapper.makeScope(o.scope);
if (this.class.hasNameClash) { if (this.class.hasNameClash) {
@ -2947,7 +2947,7 @@
return ExecutableClassBody; return ExecutableClassBody;
})(); }).call(this);
//### Import and Export //### Import and Export
exports.ModuleDeclaration = ModuleDeclaration = (function() { exports.ModuleDeclaration = ModuleDeclaration = (function() {
@ -2983,7 +2983,7 @@
return ModuleDeclaration; return ModuleDeclaration;
})(); }).call(this);
exports.ImportDeclaration = ImportDeclaration = class ImportDeclaration extends ModuleDeclaration { exports.ImportDeclaration = ImportDeclaration = class ImportDeclaration extends ModuleDeclaration {
compileNode(o) { compileNode(o) {
@ -3036,7 +3036,7 @@
return ImportClause; return ImportClause;
})(); }).call(this);
exports.ExportDeclaration = ExportDeclaration = class ExportDeclaration extends ModuleDeclaration { exports.ExportDeclaration = ExportDeclaration = class ExportDeclaration extends ModuleDeclaration {
compileNode(o) { compileNode(o) {
@ -3118,7 +3118,7 @@
return ModuleSpecifierList; return ModuleSpecifierList;
})(); }).call(this);
exports.ImportSpecifierList = ImportSpecifierList = class ImportSpecifierList extends ModuleSpecifierList {}; exports.ImportSpecifierList = ImportSpecifierList = class ImportSpecifierList extends ModuleSpecifierList {};
@ -3162,7 +3162,7 @@
return ModuleSpecifier; return ModuleSpecifier;
})(); }).call(this);
exports.ImportSpecifier = ImportSpecifier = class ImportSpecifier extends ModuleSpecifier { exports.ImportSpecifier = ImportSpecifier = class ImportSpecifier extends ModuleSpecifier {
constructor(imported, local) { constructor(imported, local) {
@ -3730,7 +3730,7 @@
return Assign; return Assign;
})(); }).call(this);
//### FuncGlyph //### FuncGlyph
exports.FuncGlyph = FuncGlyph = class FuncGlyph extends Base { exports.FuncGlyph = FuncGlyph = class FuncGlyph extends Base {
@ -4186,7 +4186,7 @@
return Code; return Code;
})(); }).call(this);
//### Param //### Param
@ -4329,7 +4329,7 @@
return Param; return Param;
})(); }).call(this);
//### Splat //### Splat
@ -4364,7 +4364,7 @@
return Splat; return Splat;
})(); }).call(this);
//### Expansion //### Expansion
@ -4388,7 +4388,7 @@
return Expansion; return Expansion;
})(); }).call(this);
//### Elision //### Elision
@ -4420,7 +4420,7 @@
return Elision; return Elision;
})(); }).call(this);
//### While //### While
@ -4507,7 +4507,7 @@
return While; return While;
})(); }).call(this);
//### Op //### Op
@ -4805,7 +4805,7 @@
return Op; return Op;
})(); }).call(this);
//### In //### In
exports.In = In = (function() { exports.In = In = (function() {
@ -4883,7 +4883,7 @@
return In; return In;
})(); }).call(this);
//### Try //### Try
@ -4936,7 +4936,7 @@
return Try; return Try;
})(); }).call(this);
//### Throw //### Throw
@ -4970,7 +4970,7 @@
return Throw; return Throw;
})(); }).call(this);
//### Existence //### Existence
@ -5030,7 +5030,7 @@
return Existence; return Existence;
})(); }).call(this);
//### Parens //### Parens
@ -5087,7 +5087,7 @@
return Parens; return Parens;
})(); }).call(this);
//### StringWithInterpolations //### StringWithInterpolations
exports.StringWithInterpolations = StringWithInterpolations = (function() { exports.StringWithInterpolations = StringWithInterpolations = (function() {
@ -5213,7 +5213,7 @@
return StringWithInterpolations; return StringWithInterpolations;
})(); }).call(this);
//### For //### For
@ -5461,7 +5461,7 @@
return For; return For;
})(); }).call(this);
//### Switch //### Switch
@ -5548,7 +5548,7 @@
return Switch; return Switch;
})(); }).call(this);
//### If //### If
@ -5685,7 +5685,7 @@
return If; return If;
})(); }).call(this);
// Constants // Constants
// --------- // ---------

View file

@ -886,7 +886,7 @@
return Rewriter; return Rewriter;
})(); }).call(this);
// Constants // Constants
// --------- // ---------

View file

@ -203,7 +203,7 @@
return SourceMap; return SourceMap;
})(); }).call(this);
// Our API for source maps is just the `SourceMap` class. // Our API for source maps is just the `SourceMap` class.
module.exports = SourceMap; module.exports = SourceMap;

View file

@ -1877,9 +1877,9 @@ exports.ExecutableClassBody = class ExecutableClassBody extends Base
ident = new IdentifierLiteral @name ident = new IdentifierLiteral @name
params = [] params = []
args = [] args = [new ThisLiteral]
wrapper = new Code params, @body wrapper = new Code params, @body
klass = new Parens new Call wrapper, args klass = new Parens new Call (new Value wrapper, [new Access new PropertyName 'call']), args
@body.spaced = true @body.spaced = true

View file

@ -1857,3 +1857,13 @@ test "#4724: backticked expression in a class body with hoisted member", ->
a = new A a = new A
eq 42, a.x eq 42, a.x
eq 84, a.hoisted eq 84, a.hoisted
test "#4827: executable class body wrappers have correct context", ->
test = ->
class @A
class @B extends @A
@property = 1
o = {}
test.call o
ok typeof o.A is typeof o.B is 'function'

View file

@ -364,7 +364,7 @@ test "#3132: Place block-comments nicely", ->
return DummyClass; return DummyClass;
})();""" }).call(this);"""
test "#3638: Demand a whitespace after # symbol", -> test "#3638: Demand a whitespace after # symbol", ->
eqJS """ eqJS """