|
|
@@ -61,6 +61,8 @@ class TSLEncoder {
|
|
|
this.uniqueNames = false;
|
|
|
this.reference = false;
|
|
|
|
|
|
+ this._currentVarible = null;
|
|
|
+
|
|
|
this._currentProperties = {};
|
|
|
this._lastStatement = null;
|
|
|
|
|
|
@@ -321,9 +323,22 @@ class TSLEncoder {
|
|
|
|
|
|
let type = unaryLib[ node.type ];
|
|
|
|
|
|
- if ( node.after === false && ( node.type === '++' || node.type === '--' ) ) {
|
|
|
+ if ( node.type === '++' || node.type === '--' ) {
|
|
|
+
|
|
|
+ if ( this._currentVarible === null ) {
|
|
|
+
|
|
|
+ // optimize increment/decrement operator
|
|
|
+ // to avoid creating a new variable
|
|
|
+
|
|
|
+ node.after = false;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( node.after === false ) {
|
|
|
+
|
|
|
+ type += 'Before';
|
|
|
|
|
|
- type += 'Before';
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -476,8 +491,10 @@ ${ this.tab }} )`;
|
|
|
|
|
|
if ( ( initialization && initialization.isVariableDeclaration && initialization.next === null ) &&
|
|
|
( condition && condition.left.isAccessor && condition.left.property === initialization.name ) &&
|
|
|
- ( afterthought && afterthought.isUnary ) &&
|
|
|
- ( initialization.name === afterthought.expression.property )
|
|
|
+ ( afterthought && (
|
|
|
+ ( afterthought.isUnary && ( initialization.name === afterthought.expression.property ) ) ||
|
|
|
+ ( afterthought.isOperator && ( initialization.name === afterthought.left.property ) )
|
|
|
+ ) )
|
|
|
) {
|
|
|
|
|
|
return this.emitLoop( node );
|
|
|
@@ -497,7 +514,7 @@ ${ this.tab }} )`;
|
|
|
this.tab += '\t';
|
|
|
|
|
|
let forStr = '{\n\n' + this.tab + initialization + ';\n\n';
|
|
|
- forStr += `${ this.tab }While( ${ condition }, () => {\n\n`;
|
|
|
+ forStr += `${ this.tab }Loop( ${ condition }, () => {\n\n`;
|
|
|
|
|
|
forStr += this.emitBody( node.body ) + '\n\n';
|
|
|
|
|
|
@@ -509,7 +526,7 @@ ${ this.tab }} )`;
|
|
|
|
|
|
forStr += this.tab + '}';
|
|
|
|
|
|
- this.imports.add( 'While' );
|
|
|
+ this.imports.add( 'Loop' );
|
|
|
|
|
|
return forStr;
|
|
|
|
|
|
@@ -519,6 +536,8 @@ ${ this.tab }} )`;
|
|
|
|
|
|
const { name, type, value, next } = node;
|
|
|
|
|
|
+ this._currentVarible = node;
|
|
|
+
|
|
|
const valueStr = value ? this.emitExpression( value ) : '';
|
|
|
|
|
|
let varStr = isRoot ? 'const ' : '';
|
|
|
@@ -556,6 +575,8 @@ ${ this.tab }} )`;
|
|
|
|
|
|
this.addImport( type );
|
|
|
|
|
|
+ this._currentVarible = null;
|
|
|
+
|
|
|
return varStr;
|
|
|
|
|
|
}
|