Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions escodegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,17 @@
result = join(result, this.generateExpression(stmt.id, Precedence.Sequence, E_TTT));
}
if (stmt.superClass) {
fragment = join('extends', this.generateExpression(stmt.superClass, Precedence.Assignment, E_TTT));
var superClassExpression = this.generateExpression(stmt.superClass, Precedence.Assignment, E_TTT);
var superClassStmtType = stmt.superClass.type;

if (
superClassStmtType === Syntax.AssignmentExpression
|| superClassStmtType === Syntax.LogicalExpression
) {
superClassExpression = ['(', space, superClassExpression, space, ')'];
}

fragment = join('extends', superClassExpression);
result = join(result, fragment);
}
result.push(space);
Expand Down Expand Up @@ -2095,7 +2105,17 @@
result = join(result, this.generateExpression(expr.id, Precedence.Sequence, E_TTT));
}
if (expr.superClass) {
fragment = join('extends', this.generateExpression(expr.superClass, Precedence.Assignment, E_TTT));
var superClassExpression = this.generateExpression(expr.superClass, Precedence.Assignment, E_TTT);
var superClassStmtType = expr.superClass.type;

if (
superClassStmtType === Syntax.AssignmentExpression
|| superClassStmtType === Syntax.LogicalExpression
) {
superClassExpression = ['(', space, superClassExpression, space, ')'];
}

fragment = join('extends', superClassExpression);
result = join(result, fragment);
}
result.push(space);
Expand Down
326 changes: 326 additions & 0 deletions test/harmony.js
Original file line number Diff line number Diff line change
Expand Up @@ -3016,6 +3016,128 @@ data = {
}
},

'class hello extends([]||[]){}': {
options: {
format: {
compact: true,
semicolons: false
}
},
generateFrom: {
type: 'Program',
body: [{
type: 'ClassDeclaration',
id: {
type: 'Identifier',
name: 'hello',
range: [6, 11],
loc: {
start: { line: 1, column: 6 },
end: { line: 1, column: 11 }
}
},
superClass: {
type: 'LogicalExpression',
start: 47,
end: 55,
left: {
type: 'ArrayExpression',
start: 47,
end: 49,
elements: []
},
operator: '||',
right: {
type: 'ArrayExpression',
start: 53,
end: 55,
elements: []
},
},
body: {
type: 'ClassBody',
body: [],
range: [21, 23],
loc: {
start: { line: 1, column: 21 },
end: { line: 1, column: 23 }
}
},
range: [0, 23],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 23 }
}
}],
range: [0, 23],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 23 }
}
}
},

'class hello extends([]=[]){}': {
options: {
format: {
compact: true,
semicolons: false
}
},
generateFrom: {
type: 'Program',
body: [{
type: 'ClassDeclaration',
id: {
type: 'Identifier',
name: 'hello',
range: [6, 11],
loc: {
start: { line: 1, column: 6 },
end: { line: 1, column: 11 }
}
},
superClass: {
type: 'AssignmentExpression',
start: 47,
end: 55,
left: {
type: 'ArrayExpression',
start: 47,
end: 49,
elements: []
},
operator: '=',
right: {
type: 'ArrayExpression',
start: 53,
end: 55,
elements: []
},
},
body: {
type: 'ClassBody',
body: [],
range: [21, 23],
loc: {
start: { line: 1, column: 21 },
end: { line: 1, column: 23 }
}
},
range: [0, 23],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 23 }
}
}],
range: [0, 23],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 23 }
}
}
},

'class hello extends[]{static[ok](){}}': {
options: {
format: {
Expand Down Expand Up @@ -4125,6 +4247,210 @@ data = {
}
},

'(class extends([]||[]){static[ok](){}})': {
options: {
format: {
compact: true,
semicolons: false
}
},
generateFrom: {
type: 'Program',
body: [{
type: 'ExpressionStatement',
expression: {
type: 'ClassExpression',
superClass: {
type: 'LogicalExpression',
start: 47,
end: 55,
left: {
type: 'ArrayExpression',
start: 47,
end: 49,
elements: []
},
operator: '||',
right: {
type: 'ArrayExpression',
start: 53,
end: 55,
elements: []
},
},
body: {
type: 'ClassBody',
body: [{
type: 'MethodDefinition',
key: {
type: 'Identifier',
name: 'ok',
range: [24, 26],
loc: {
start: { line: 1, column: 24 },
end: { line: 1, column: 26 }
}
},
value: {
type: 'FunctionExpression',
id: null,
params: [],
defaults: [],
body: {
type: 'BlockStatement',
body: [],
range: [29, 31],
loc: {
start: { line: 1, column: 29 },
end: { line: 1, column: 31 }
}
},
rest: null,
generator: false,
expression: false,
range: [29, 31],
loc: {
start: { line: 1, column: 29 },
end: { line: 1, column: 31 }
}
},
kind: '',
'static': true,
computed: true,
range: [17, 31],
loc: {
start: { line: 1, column: 17 },
end: { line: 1, column: 31 }
}
}],
range: [16, 32],
loc: {
start: { line: 1, column: 16 },
end: { line: 1, column: 32 }
}
},
range: [1, 32],
loc: {
start: { line: 1, column: 1 },
end: { line: 1, column: 32 }
}
},
range: [0, 33],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 33 }
}
}],
range: [0, 33],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 33 }
}
}
},

'(class extends([]=[]){static[ok](){}})': {
options: {
format: {
compact: true,
semicolons: false
}
},
generateFrom: {
type: 'Program',
body: [{
type: 'ExpressionStatement',
expression: {
type: 'ClassExpression',
superClass: {
type: 'AssignmentExpression',
start: 47,
end: 55,
left: {
type: 'ArrayExpression',
start: 47,
end: 49,
elements: []
},
operator: '=',
right: {
type: 'ArrayExpression',
start: 53,
end: 55,
elements: []
},
},
body: {
type: 'ClassBody',
body: [{
type: 'MethodDefinition',
key: {
type: 'Identifier',
name: 'ok',
range: [24, 26],
loc: {
start: { line: 1, column: 24 },
end: { line: 1, column: 26 }
}
},
value: {
type: 'FunctionExpression',
id: null,
params: [],
defaults: [],
body: {
type: 'BlockStatement',
body: [],
range: [29, 31],
loc: {
start: { line: 1, column: 29 },
end: { line: 1, column: 31 }
}
},
rest: null,
generator: false,
expression: false,
range: [29, 31],
loc: {
start: { line: 1, column: 29 },
end: { line: 1, column: 31 }
}
},
kind: '',
'static': true,
computed: true,
range: [17, 31],
loc: {
start: { line: 1, column: 17 },
end: { line: 1, column: 31 }
}
}],
range: [16, 32],
loc: {
start: { line: 1, column: 16 },
end: { line: 1, column: 32 }
}
},
range: [1, 32],
loc: {
start: { line: 1, column: 1 },
end: { line: 1, column: 32 }
}
},
range: [0, 33],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 33 }
}
}],
range: [0, 33],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 33 }
}
}
},

'(class extends"hello"{static[ok](){}})': {
options: {
format: {
Expand Down