Skip to content

Commit dd94b15

Browse files
author
shenlibo
committed
Add support Class field declarations
1 parent 2e4b6bf commit dd94b15

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

escodegen.js

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@
314314
temp += 'e' + exponent;
315315
}
316316
if ((temp.length < result.length ||
317-
(hexadecimal && value > 1e12 && Math.floor(value) === value && (temp = '0x' + value.toString(16)).length < result.length)) &&
318-
+temp === value) {
317+
(hexadecimal && value > 1e12 && Math.floor(value) === value && (temp = '0x' + value.toString(16)).length < result.length)) &&
318+
+temp === value) {
319319
result = temp;
320320
}
321321

@@ -564,7 +564,7 @@
564564
leftCharCode === 0x2F /* / */ && rightCharCode === 0x69 /* i */) { // infix word operators all start with `i`
565565
return [left, noEmptySpace(), right];
566566
} else if (esutils.code.isWhiteSpace(leftCharCode) || esutils.code.isLineTerminator(leftCharCode) ||
567-
esutils.code.isWhiteSpace(rightCharCode) || esutils.code.isLineTerminator(rightCharCode)) {
567+
esutils.code.isWhiteSpace(rightCharCode) || esutils.code.isLineTerminator(rightCharCode)) {
568568
return [left, right];
569569
}
570570
return [left, space, right];
@@ -827,7 +827,7 @@
827827

828828
// Helpers.
829829

830-
CodeGenerator.prototype.maybeBlock = function(stmt, flags) {
830+
CodeGenerator.prototype.maybeBlock = function (stmt, flags) {
831831
var result, noLeadingComment, that = this;
832832

833833
noLeadingComment = !extra.comment || !stmt.leadingComments;
@@ -899,8 +899,8 @@
899899
hasDefault = false;
900900

901901
if (node.type === Syntax.ArrowFunctionExpression &&
902-
!node.rest && (!node.defaults || node.defaults.length === 0) &&
903-
node.params.length === 1 && node.params[0].type === Syntax.Identifier) {
902+
!node.rest && (!node.defaults || node.defaults.length === 0) &&
903+
node.params.length === 1 && node.params[0].type === Syntax.Identifier) {
904904
// arg => { } case
905905
result = [generateAsyncPrefix(node, true), generateIdentifier(node.params[0])];
906906
} else {
@@ -1064,7 +1064,7 @@
10641064

10651065
// handle spaces between lines
10661066
if (i > 0) {
1067-
if (!stmt.body[i - 1].trailingComments && !stmt.body[i].leadingComments) {
1067+
if (!stmt.body[i - 1].trailingComments && !stmt.body[i].leadingComments) {
10681068
generateBlankLines(stmt.body[i - 1].range[1], stmt.body[i].range[0], result);
10691069
}
10701070
}
@@ -1123,7 +1123,7 @@
11231123
},
11241124

11251125
ClassBody: function (stmt, flags) {
1126-
var result = [ '{', newline], that = this;
1126+
var result = ['{', newline], that = this;
11271127

11281128
withIndent(function (indent) {
11291129
var i, iz;
@@ -1147,7 +1147,7 @@
11471147

11481148
ClassDeclaration: function (stmt, flags) {
11491149
var result, fragment;
1150-
result = ['class'];
1150+
result = ['class'];
11511151
if (stmt.id) {
11521152
result = join(result, this.generateExpression(stmt.id, Precedence.Sequence, E_TTT));
11531153
}
@@ -1211,7 +1211,7 @@
12111211
},
12121212

12131213
ExportDefaultDeclaration: function (stmt, flags) {
1214-
var result = [ 'export' ], bodyFlags;
1214+
var result = ['export'], bodyFlags;
12151215

12161216
bodyFlags = (flags & F_SEMICOLON_OPT) ? S_TFFT : S_TFFF;
12171217

@@ -1227,7 +1227,7 @@
12271227
},
12281228

12291229
ExportNamedDeclaration: function (stmt, flags) {
1230-
var result = [ 'export' ], bodyFlags, that = this;
1230+
var result = ['export'], bodyFlags, that = this;
12311231

12321232
bodyFlags = (flags & F_SEMICOLON_OPT) ? S_TFFT : S_TFFF;
12331233

@@ -1338,10 +1338,10 @@
13381338
// wrap expression with parentheses
13391339
fragment = toSourceNodeWhenNeeded(result).toString();
13401340
if (fragment.charCodeAt(0) === 0x7B /* '{' */ || // ObjectExpression
1341-
isClassPrefixed(fragment) ||
1342-
isFunctionPrefixed(fragment) ||
1343-
isAsyncPrefixed(fragment) ||
1344-
(directive && (flags & F_DIRECTIVE_CTX) && stmt.expression.type === Syntax.Literal && typeof stmt.expression.value === 'string')) {
1341+
isClassPrefixed(fragment) ||
1342+
isFunctionPrefixed(fragment) ||
1343+
isAsyncPrefixed(fragment) ||
1344+
(directive && (flags & F_DIRECTIVE_CTX) && stmt.expression.type === Syntax.Literal && typeof stmt.expression.value === 'string')) {
13451345
result = ['(', result, ')' + this.semicolon(flags)];
13461346
} else {
13471347
result.push(this.semicolon(flags));
@@ -1378,7 +1378,7 @@
13781378
// ImportedBinding
13791379
if (stmt.specifiers[cursor].type === Syntax.ImportDefaultSpecifier) {
13801380
result = join(result, [
1381-
this.generateExpression(stmt.specifiers[cursor], Precedence.Sequence, E_TTT)
1381+
this.generateExpression(stmt.specifiers[cursor], Precedence.Sequence, E_TTT)
13821382
]);
13831383
++cursor;
13841384
}
@@ -1391,8 +1391,8 @@
13911391
if (stmt.specifiers[cursor].type === Syntax.ImportNamespaceSpecifier) {
13921392
// NameSpaceImport
13931393
result = join(result, [
1394-
space,
1395-
this.generateExpression(stmt.specifiers[cursor], Precedence.Sequence, E_TTT)
1394+
space,
1395+
this.generateExpression(stmt.specifiers[cursor], Precedence.Sequence, E_TTT)
13961396
]);
13971397
} else {
13981398
// NamedImports
@@ -1456,7 +1456,7 @@
14561456
// So if comment is attached to target node, we should specialize.
14571457
var result, i, iz, node, bodyFlags, that = this;
14581458

1459-
result = [ stmt.kind ];
1459+
result = [stmt.kind];
14601460

14611461
bodyFlags = (flags & F_ALLOW_IN) ? S_TFFF : S_FFFF;
14621462

@@ -1863,7 +1863,7 @@
18631863
fragment = this.generateExpression(expr.right, rightPrecedence, flags);
18641864

18651865
if (expr.operator === '/' && fragment.toString().charAt(0) === '/' ||
1866-
expr.operator.slice(-1) === '<' && fragment.toString().slice(0, 3) === '!--') {
1866+
expr.operator.slice(-1) === '<' && fragment.toString().slice(0, 3) === '!--') {
18671867
// If '/' concats with '/' or `<` concats with `!--`, it is interpreted as comment start
18681868
result.push(noEmptySpace());
18691869
result.push(fragment);
@@ -1967,11 +1967,11 @@
19671967
// 4. Not hexadecimal OR octal number literal
19681968
// we should add a floating point.
19691969
if (
1970-
fragment.indexOf('.') < 0 &&
1971-
!/[eExX]/.test(fragment) &&
1972-
esutils.code.isDecimalDigit(fragment.charCodeAt(fragment.length - 1)) &&
1973-
!(fragment.length >= 2 && fragment.charCodeAt(0) === 48) // '0'
1974-
) {
1970+
fragment.indexOf('.') < 0 &&
1971+
!/[eExX]/.test(fragment) &&
1972+
esutils.code.isDecimalDigit(fragment.charCodeAt(fragment.length - 1)) &&
1973+
!(fragment.length >= 2 && fragment.charCodeAt(0) === 48) // '0'
1974+
) {
19751975
result.push(' ');
19761976
}
19771977
}
@@ -2011,7 +2011,7 @@
20112011
rightCharCode = fragment.toString().charCodeAt(0);
20122012

20132013
if (((leftCharCode === 0x2B /* + */ || leftCharCode === 0x2D /* - */) && leftCharCode === rightCharCode) ||
2014-
(esutils.code.isIdentifierPartES5(leftCharCode) && esutils.code.isIdentifierPartES5(rightCharCode))) {
2014+
(esutils.code.isIdentifierPartES5(leftCharCode) && esutils.code.isIdentifierPartES5(rightCharCode))) {
20152015
result.push(noEmptySpace());
20162016
result.push(fragment);
20172017
} else {
@@ -2120,7 +2120,7 @@
21202120
return result;
21212121
},
21222122

2123-
RestElement: function(expr, precedence, flags) {
2123+
RestElement: function (expr, precedence, flags) {
21242124
return '...' + this.generatePattern(expr.argument);
21252125
},
21262126

@@ -2161,24 +2161,24 @@
21612161
return join(result, fragment);
21622162
},
21632163

2164-
FieldDefinition: function(expr, precedence, flags) {
2164+
FieldDefinition: function (expr, precedence, flags) {
21652165
var result;
2166-
if (expr.static) {
2167-
result = [`static${space}`];
2166+
if (expr['static']) {
2167+
result = ['static' + space];
21682168
}
21692169
else {
21702170
result = [];
21712171
}
21722172
var fragment = [
21732173
this.generatePropertyKey(expr.key, expr.computed),
2174-
`${space}=${space}`,
2174+
space + '=' + space,
21752175
this.generateExpression(expr.value, Precedence.Assignment, E_TTT)
21762176
];
21772177
return join(result, fragment);
21782178
},
21792179

2180-
PrivateName: function(expr, precedence, flags) {
2181-
return toSourceNodeWhenNeeded(`#${expr.name}`, expr);
2180+
PrivateName: function (expr, precedence, flags) {
2181+
return toSourceNodeWhenNeeded('#' + expr.name, expr);
21822182
},
21832183

21842184
Property: function (expr, precedence, flags) {
@@ -2234,13 +2234,13 @@
22342234
// dejavu.Class.declare({method2: function () {
22352235
// }});
22362236
if (!hasLineTerminator(toSourceNodeWhenNeeded(fragment).toString())) {
2237-
return [ '{', space, fragment, space, '}' ];
2237+
return ['{', space, fragment, space, '}'];
22382238
}
22392239
}
22402240

22412241
withIndent(function (indent) {
22422242
var i, iz;
2243-
result = [ '{', newline, indent, fragment ];
2243+
result = ['{', newline, indent, fragment];
22442244

22452245
if (multiline) {
22462246
result.push(',' + newline);
@@ -2262,7 +2262,7 @@
22622262
return result;
22632263
},
22642264

2265-
AssignmentPattern: function(expr, precedence, flags) {
2265+
AssignmentPattern: function (expr, precedence, flags) {
22662266
return this.generateAssignment(expr.left, expr.right, '=', precedence, flags);
22672267
},
22682268

@@ -2293,7 +2293,7 @@
22932293
}
22942294
}
22952295
}
2296-
result = ['{', multiline ? newline : '' ];
2296+
result = ['{', multiline ? newline : ''];
22972297

22982298
withIndent(function (indent) {
22992299
var i, iz;
@@ -2341,7 +2341,7 @@
23412341

23422342
ImportSpecifier: function (expr, precedence, flags) {
23432343
var imported = expr.imported;
2344-
var result = [ imported.name ];
2344+
var result = [imported.name];
23452345
var local = expr.local;
23462346
if (local && local.name !== imported.name) {
23472347
result.push(noEmptySpace() + 'as' + noEmptySpace() + generateIdentifier(local));
@@ -2351,7 +2351,7 @@
23512351

23522352
ExportSpecifier: function (expr, precedence, flags) {
23532353
var local = expr.local;
2354-
var result = [ local.name ];
2354+
var result = [local.name];
23552355
var exported = expr.exported;
23562356
if (exported && exported.name !== local.name) {
23572357
result.push(noEmptySpace() + 'as' + noEmptySpace() + generateIdentifier(exported));
@@ -2375,7 +2375,7 @@
23752375
}
23762376

23772377
if (expr.regex) {
2378-
return '/' + expr.regex.pattern + '/' + expr.regex.flags;
2378+
return '/' + expr.regex.pattern + '/' + expr.regex.flags;
23792379
}
23802380

23812381
if (typeof expr.value === 'bigint') {
@@ -2439,7 +2439,7 @@
24392439
if (expr.filter) {
24402440
result = join(result, 'if' + space);
24412441
fragment = this.generateExpression(expr.filter, Precedence.Sequence, E_TTT);
2442-
result = join(result, [ '(', fragment, ')' ]);
2442+
result = join(result, ['(', fragment, ')']);
24432443
}
24442444

24452445
if (!extra.moz.comprehensionExpressionStartsWithAssignment) {
@@ -2466,7 +2466,7 @@
24662466
fragment = join(fragment, expr.of ? 'of' : 'in');
24672467
fragment = join(fragment, this.generateExpression(expr.right, Precedence.Sequence, E_TTT));
24682468

2469-
return [ 'for' + space + '(', fragment, ')' ];
2469+
return ['for' + space + '(', fragment, ')'];
24702470
},
24712471

24722472
SpreadElement: function (expr, precedence, flags) {
@@ -2496,7 +2496,7 @@
24962496

24972497
TemplateLiteral: function (expr, precedence, flags) {
24982498
var result, i, iz;
2499-
result = [ '`' ];
2499+
result = ['`'];
25002500
for (i = 0, iz = expr.quasis.length; i < iz; ++i) {
25012501
result.push(this.generateExpression(expr.quasis[i], Precedence.Primary, E_TTT));
25022502
if (i + 1 < iz) {
@@ -2513,7 +2513,7 @@
25132513
return this.Literal(expr, precedence, flags);
25142514
},
25152515

2516-
ImportExpression: function(expr, precedence, flag) {
2516+
ImportExpression: function (expr, precedence, flag) {
25172517
return parenthesize([
25182518
'import(',
25192519
this.generateExpression(expr.source, Precedence.Assignment, E_TTT),
@@ -2555,7 +2555,7 @@
25552555
}
25562556

25572557
fragment = toSourceNodeWhenNeeded(result).toString();
2558-
if (stmt.type === Syntax.Program && !safeConcatenation && newline === '' && fragment.charAt(fragment.length - 1) === '\n') {
2558+
if (stmt.type === Syntax.Program && !safeConcatenation && newline === '' && fragment.charAt(fragment.length - 1) === '\n') {
25592559
result = sourceMap ? toSourceNodeWhenNeeded(result).replaceRight(/\s+$/, '') : fragment.replace(/\s+$/, '');
25602560
}
25612561

@@ -2638,7 +2638,7 @@
26382638
result = generateInternal(node);
26392639

26402640
if (!sourceMap) {
2641-
pair = {code: result.toString(), map: null};
2641+
pair = { code: result.toString(), map: null };
26422642
return options.sourceMapWithCode ? pair : pair.code;
26432643
}
26442644

@@ -2650,7 +2650,7 @@
26502650

26512651
if (options.sourceContent) {
26522652
pair.map.setSourceContent(options.sourceMap,
2653-
options.sourceContent);
2653+
options.sourceContent);
26542654
}
26552655

26562656
if (options.sourceMapWithCode) {

0 commit comments

Comments
 (0)