|
1268 | 1268 | ExpressionStatement: function (stmt, flags) { |
1269 | 1269 | var result, fragment; |
1270 | 1270 |
|
| 1271 | + function isClassPrefixed(fragment) { |
| 1272 | + var code; |
| 1273 | + if (fragment.slice(0, 5) !== 'class') { |
| 1274 | + return false; |
| 1275 | + } |
| 1276 | + code = fragment.charCodeAt(5); |
| 1277 | + return code === 0x7B /* '{' */ || esutils.code.isWhiteSpace(code) || esutils.code.isLineTerminator(code); |
| 1278 | + } |
| 1279 | + |
| 1280 | + function isFunctionPrefixed(fragment) { |
| 1281 | + var code; |
| 1282 | + if (fragment.slice(0, 8) !== 'function') { |
| 1283 | + return false; |
| 1284 | + } |
| 1285 | + code = fragment.charCodeAt(8); |
| 1286 | + return code === 0x28 /* '(' */ || esutils.code.isWhiteSpace(code) || code === 0x2A /* '*' */ || esutils.code.isLineTerminator(code); |
| 1287 | + } |
| 1288 | + |
| 1289 | + function isAsyncPrefixed(fragment) { |
| 1290 | + var code, i, iz; |
| 1291 | + if (fragment.slice(0, 5) !== 'async') { |
| 1292 | + return false; |
| 1293 | + } |
| 1294 | + if (!esutils.code.isWhiteSpace(fragment.charCodeAt(5))) { |
| 1295 | + return false; |
| 1296 | + } |
| 1297 | + for (i = 6, iz = fragment.length; i < iz; ++i) { |
| 1298 | + if (!esutils.code.isWhiteSpace(fragment.charCodeAt(i))) { |
| 1299 | + break; |
| 1300 | + } |
| 1301 | + } |
| 1302 | + if (i === iz) { |
| 1303 | + return false; |
| 1304 | + } |
| 1305 | + if (fragment.slice(i, i + 8) !== 'function') { |
| 1306 | + return false; |
| 1307 | + } |
| 1308 | + code = fragment.charCodeAt(i + 8); |
| 1309 | + return code === 0x28 /* '(' */ || esutils.code.isWhiteSpace(code) || code === 0x2A /* '*' */ || esutils.code.isLineTerminator(code); |
| 1310 | + } |
| 1311 | + |
1271 | 1312 | result = [this.generateExpression(stmt.expression, Precedence.Sequence, E_TTT)]; |
1272 | 1313 | // 12.4 '{', 'function', 'class' is not allowed in this position. |
1273 | 1314 | // wrap expression with parentheses |
1274 | 1315 | fragment = toSourceNodeWhenNeeded(result).toString(); |
1275 | | - if (fragment.charAt(0) === '{' || // ObjectExpression |
1276 | | - (fragment.slice(0, 5) === 'class' && ' {'.indexOf(fragment.charAt(5)) >= 0) || // class |
1277 | | - (fragment.slice(0, 8) === 'function' && '* ('.indexOf(fragment.charAt(8)) >= 0) || // function or generator |
| 1316 | + if (fragment.charCodeAt(0) === 0x7B /* '{' */ || // ObjectExpression |
| 1317 | + isClassPrefixed(fragment) || |
| 1318 | + isFunctionPrefixed(fragment) || |
| 1319 | + isAsyncPrefixed(fragment) || |
1278 | 1320 | (directive && (flags & F_DIRECTIVE_CTX) && stmt.expression.type === Syntax.Literal && typeof stmt.expression.value === 'string')) { |
1279 | 1321 | result = ['(', result, ')' + this.semicolon(flags)]; |
1280 | 1322 | } else { |
|
0 commit comments