|
314 | 314 | temp += 'e' + exponent; |
315 | 315 | } |
316 | 316 | 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) { |
319 | 319 | result = temp; |
320 | 320 | } |
321 | 321 |
|
|
564 | 564 | leftCharCode === 0x2F /* / */ && rightCharCode === 0x69 /* i */) { // infix word operators all start with `i` |
565 | 565 | return [left, noEmptySpace(), right]; |
566 | 566 | } 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)) { |
568 | 568 | return [left, right]; |
569 | 569 | } |
570 | 570 | return [left, space, right]; |
|
827 | 827 |
|
828 | 828 | // Helpers. |
829 | 829 |
|
830 | | - CodeGenerator.prototype.maybeBlock = function(stmt, flags) { |
| 830 | + CodeGenerator.prototype.maybeBlock = function (stmt, flags) { |
831 | 831 | var result, noLeadingComment, that = this; |
832 | 832 |
|
833 | 833 | noLeadingComment = !extra.comment || !stmt.leadingComments; |
|
899 | 899 | hasDefault = false; |
900 | 900 |
|
901 | 901 | 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) { |
904 | 904 | // arg => { } case |
905 | 905 | result = [generateAsyncPrefix(node, true), generateIdentifier(node.params[0])]; |
906 | 906 | } else { |
|
1064 | 1064 |
|
1065 | 1065 | // handle spaces between lines |
1066 | 1066 | 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) { |
1068 | 1068 | generateBlankLines(stmt.body[i - 1].range[1], stmt.body[i].range[0], result); |
1069 | 1069 | } |
1070 | 1070 | } |
|
1123 | 1123 | }, |
1124 | 1124 |
|
1125 | 1125 | ClassBody: function (stmt, flags) { |
1126 | | - var result = [ '{', newline], that = this; |
| 1126 | + var result = ['{', newline], that = this; |
1127 | 1127 |
|
1128 | 1128 | withIndent(function (indent) { |
1129 | 1129 | var i, iz; |
|
1147 | 1147 |
|
1148 | 1148 | ClassDeclaration: function (stmt, flags) { |
1149 | 1149 | var result, fragment; |
1150 | | - result = ['class']; |
| 1150 | + result = ['class']; |
1151 | 1151 | if (stmt.id) { |
1152 | 1152 | result = join(result, this.generateExpression(stmt.id, Precedence.Sequence, E_TTT)); |
1153 | 1153 | } |
|
1211 | 1211 | }, |
1212 | 1212 |
|
1213 | 1213 | ExportDefaultDeclaration: function (stmt, flags) { |
1214 | | - var result = [ 'export' ], bodyFlags; |
| 1214 | + var result = ['export'], bodyFlags; |
1215 | 1215 |
|
1216 | 1216 | bodyFlags = (flags & F_SEMICOLON_OPT) ? S_TFFT : S_TFFF; |
1217 | 1217 |
|
|
1227 | 1227 | }, |
1228 | 1228 |
|
1229 | 1229 | ExportNamedDeclaration: function (stmt, flags) { |
1230 | | - var result = [ 'export' ], bodyFlags, that = this; |
| 1230 | + var result = ['export'], bodyFlags, that = this; |
1231 | 1231 |
|
1232 | 1232 | bodyFlags = (flags & F_SEMICOLON_OPT) ? S_TFFT : S_TFFF; |
1233 | 1233 |
|
|
1338 | 1338 | // wrap expression with parentheses |
1339 | 1339 | fragment = toSourceNodeWhenNeeded(result).toString(); |
1340 | 1340 | 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')) { |
1345 | 1345 | result = ['(', result, ')' + this.semicolon(flags)]; |
1346 | 1346 | } else { |
1347 | 1347 | result.push(this.semicolon(flags)); |
|
1378 | 1378 | // ImportedBinding |
1379 | 1379 | if (stmt.specifiers[cursor].type === Syntax.ImportDefaultSpecifier) { |
1380 | 1380 | result = join(result, [ |
1381 | | - this.generateExpression(stmt.specifiers[cursor], Precedence.Sequence, E_TTT) |
| 1381 | + this.generateExpression(stmt.specifiers[cursor], Precedence.Sequence, E_TTT) |
1382 | 1382 | ]); |
1383 | 1383 | ++cursor; |
1384 | 1384 | } |
|
1391 | 1391 | if (stmt.specifiers[cursor].type === Syntax.ImportNamespaceSpecifier) { |
1392 | 1392 | // NameSpaceImport |
1393 | 1393 | 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) |
1396 | 1396 | ]); |
1397 | 1397 | } else { |
1398 | 1398 | // NamedImports |
|
1456 | 1456 | // So if comment is attached to target node, we should specialize. |
1457 | 1457 | var result, i, iz, node, bodyFlags, that = this; |
1458 | 1458 |
|
1459 | | - result = [ stmt.kind ]; |
| 1459 | + result = [stmt.kind]; |
1460 | 1460 |
|
1461 | 1461 | bodyFlags = (flags & F_ALLOW_IN) ? S_TFFF : S_FFFF; |
1462 | 1462 |
|
|
1863 | 1863 | fragment = this.generateExpression(expr.right, rightPrecedence, flags); |
1864 | 1864 |
|
1865 | 1865 | 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) === '!--') { |
1867 | 1867 | // If '/' concats with '/' or `<` concats with `!--`, it is interpreted as comment start |
1868 | 1868 | result.push(noEmptySpace()); |
1869 | 1869 | result.push(fragment); |
|
1967 | 1967 | // 4. Not hexadecimal OR octal number literal |
1968 | 1968 | // we should add a floating point. |
1969 | 1969 | 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 | + ) { |
1975 | 1975 | result.push(' '); |
1976 | 1976 | } |
1977 | 1977 | } |
|
2011 | 2011 | rightCharCode = fragment.toString().charCodeAt(0); |
2012 | 2012 |
|
2013 | 2013 | 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))) { |
2015 | 2015 | result.push(noEmptySpace()); |
2016 | 2016 | result.push(fragment); |
2017 | 2017 | } else { |
|
2120 | 2120 | return result; |
2121 | 2121 | }, |
2122 | 2122 |
|
2123 | | - RestElement: function(expr, precedence, flags) { |
| 2123 | + RestElement: function (expr, precedence, flags) { |
2124 | 2124 | return '...' + this.generatePattern(expr.argument); |
2125 | 2125 | }, |
2126 | 2126 |
|
|
2161 | 2161 | return join(result, fragment); |
2162 | 2162 | }, |
2163 | 2163 |
|
2164 | | - FieldDefinition: function(expr, precedence, flags) { |
| 2164 | + FieldDefinition: function (expr, precedence, flags) { |
2165 | 2165 | var result; |
2166 | | - if (expr.static) { |
2167 | | - result = [`static${space}`]; |
| 2166 | + if (expr['static']) { |
| 2167 | + result = ['static' + space]; |
2168 | 2168 | } |
2169 | 2169 | else { |
2170 | 2170 | result = []; |
2171 | 2171 | } |
2172 | 2172 | var fragment = [ |
2173 | 2173 | this.generatePropertyKey(expr.key, expr.computed), |
2174 | | - `${space}=${space}`, |
| 2174 | + space + '=' + space, |
2175 | 2175 | this.generateExpression(expr.value, Precedence.Assignment, E_TTT) |
2176 | 2176 | ]; |
2177 | 2177 | return join(result, fragment); |
2178 | 2178 | }, |
2179 | 2179 |
|
2180 | | - PrivateName: function(expr, precedence, flags) { |
2181 | | - return toSourceNodeWhenNeeded(`#${expr.name}`, expr); |
| 2180 | + PrivateName: function (expr, precedence, flags) { |
| 2181 | + return toSourceNodeWhenNeeded('#' + expr.name, expr); |
2182 | 2182 | }, |
2183 | 2183 |
|
2184 | 2184 | Property: function (expr, precedence, flags) { |
|
2234 | 2234 | // dejavu.Class.declare({method2: function () { |
2235 | 2235 | // }}); |
2236 | 2236 | if (!hasLineTerminator(toSourceNodeWhenNeeded(fragment).toString())) { |
2237 | | - return [ '{', space, fragment, space, '}' ]; |
| 2237 | + return ['{', space, fragment, space, '}']; |
2238 | 2238 | } |
2239 | 2239 | } |
2240 | 2240 |
|
2241 | 2241 | withIndent(function (indent) { |
2242 | 2242 | var i, iz; |
2243 | | - result = [ '{', newline, indent, fragment ]; |
| 2243 | + result = ['{', newline, indent, fragment]; |
2244 | 2244 |
|
2245 | 2245 | if (multiline) { |
2246 | 2246 | result.push(',' + newline); |
|
2262 | 2262 | return result; |
2263 | 2263 | }, |
2264 | 2264 |
|
2265 | | - AssignmentPattern: function(expr, precedence, flags) { |
| 2265 | + AssignmentPattern: function (expr, precedence, flags) { |
2266 | 2266 | return this.generateAssignment(expr.left, expr.right, '=', precedence, flags); |
2267 | 2267 | }, |
2268 | 2268 |
|
|
2293 | 2293 | } |
2294 | 2294 | } |
2295 | 2295 | } |
2296 | | - result = ['{', multiline ? newline : '' ]; |
| 2296 | + result = ['{', multiline ? newline : '']; |
2297 | 2297 |
|
2298 | 2298 | withIndent(function (indent) { |
2299 | 2299 | var i, iz; |
|
2341 | 2341 |
|
2342 | 2342 | ImportSpecifier: function (expr, precedence, flags) { |
2343 | 2343 | var imported = expr.imported; |
2344 | | - var result = [ imported.name ]; |
| 2344 | + var result = [imported.name]; |
2345 | 2345 | var local = expr.local; |
2346 | 2346 | if (local && local.name !== imported.name) { |
2347 | 2347 | result.push(noEmptySpace() + 'as' + noEmptySpace() + generateIdentifier(local)); |
|
2351 | 2351 |
|
2352 | 2352 | ExportSpecifier: function (expr, precedence, flags) { |
2353 | 2353 | var local = expr.local; |
2354 | | - var result = [ local.name ]; |
| 2354 | + var result = [local.name]; |
2355 | 2355 | var exported = expr.exported; |
2356 | 2356 | if (exported && exported.name !== local.name) { |
2357 | 2357 | result.push(noEmptySpace() + 'as' + noEmptySpace() + generateIdentifier(exported)); |
|
2375 | 2375 | } |
2376 | 2376 |
|
2377 | 2377 | if (expr.regex) { |
2378 | | - return '/' + expr.regex.pattern + '/' + expr.regex.flags; |
| 2378 | + return '/' + expr.regex.pattern + '/' + expr.regex.flags; |
2379 | 2379 | } |
2380 | 2380 |
|
2381 | 2381 | if (typeof expr.value === 'bigint') { |
|
2439 | 2439 | if (expr.filter) { |
2440 | 2440 | result = join(result, 'if' + space); |
2441 | 2441 | fragment = this.generateExpression(expr.filter, Precedence.Sequence, E_TTT); |
2442 | | - result = join(result, [ '(', fragment, ')' ]); |
| 2442 | + result = join(result, ['(', fragment, ')']); |
2443 | 2443 | } |
2444 | 2444 |
|
2445 | 2445 | if (!extra.moz.comprehensionExpressionStartsWithAssignment) { |
|
2466 | 2466 | fragment = join(fragment, expr.of ? 'of' : 'in'); |
2467 | 2467 | fragment = join(fragment, this.generateExpression(expr.right, Precedence.Sequence, E_TTT)); |
2468 | 2468 |
|
2469 | | - return [ 'for' + space + '(', fragment, ')' ]; |
| 2469 | + return ['for' + space + '(', fragment, ')']; |
2470 | 2470 | }, |
2471 | 2471 |
|
2472 | 2472 | SpreadElement: function (expr, precedence, flags) { |
|
2496 | 2496 |
|
2497 | 2497 | TemplateLiteral: function (expr, precedence, flags) { |
2498 | 2498 | var result, i, iz; |
2499 | | - result = [ '`' ]; |
| 2499 | + result = ['`']; |
2500 | 2500 | for (i = 0, iz = expr.quasis.length; i < iz; ++i) { |
2501 | 2501 | result.push(this.generateExpression(expr.quasis[i], Precedence.Primary, E_TTT)); |
2502 | 2502 | if (i + 1 < iz) { |
|
2513 | 2513 | return this.Literal(expr, precedence, flags); |
2514 | 2514 | }, |
2515 | 2515 |
|
2516 | | - ImportExpression: function(expr, precedence, flag) { |
| 2516 | + ImportExpression: function (expr, precedence, flag) { |
2517 | 2517 | return parenthesize([ |
2518 | 2518 | 'import(', |
2519 | 2519 | this.generateExpression(expr.source, Precedence.Assignment, E_TTT), |
|
2555 | 2555 | } |
2556 | 2556 |
|
2557 | 2557 | 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') { |
2559 | 2559 | result = sourceMap ? toSourceNodeWhenNeeded(result).replaceRight(/\s+$/, '') : fragment.replace(/\s+$/, ''); |
2560 | 2560 | } |
2561 | 2561 |
|
|
2638 | 2638 | result = generateInternal(node); |
2639 | 2639 |
|
2640 | 2640 | if (!sourceMap) { |
2641 | | - pair = {code: result.toString(), map: null}; |
| 2641 | + pair = { code: result.toString(), map: null }; |
2642 | 2642 | return options.sourceMapWithCode ? pair : pair.code; |
2643 | 2643 | } |
2644 | 2644 |
|
|
2650 | 2650 |
|
2651 | 2651 | if (options.sourceContent) { |
2652 | 2652 | pair.map.setSourceContent(options.sourceMap, |
2653 | | - options.sourceContent); |
| 2653 | + options.sourceContent); |
2654 | 2654 | } |
2655 | 2655 |
|
2656 | 2656 | if (options.sourceMapWithCode) { |
|
0 commit comments