Skip to content

Commit

Permalink
babel plugin logic fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
volovyks committed Aug 30, 2022
1 parent 8d6affb commit 4a1fd14
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
15 changes: 10 additions & 5 deletions lib/build-tools/near-bindgen-exporter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions src/build-tools/near-bindgen-exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,24 @@ export default function () {
path.insertAfter(t.exportNamedDeclaration(t.functionDeclaration(t.identifier(method), [], t.blockStatement([
// const _state = Counter._getState();
t.variableDeclaration('let', [t.variableDeclarator(t.identifier('_state'), t.callExpression(t.memberExpression(classId, t.identifier('_getState')), []))]),
contractMethods[method] == 'initialize' ?
// if (_state) { throw new Error('Counter already initialized'); }
contractMethods[method] === 'initialize' ?
// if (_state) { throw new Error('Contract already initialized'); }
t.ifStatement(t.identifier('_state'), t.throwStatement(t.newExpression(t.identifier('Error'), [t.stringLiteral('Contract already initialized')])))
: t.emptyStatement(),
contractMethods[method] === 'call' || contractMethods[method] === 'view' ?
// if (!_state) { throw new Error('Contract must be initialized'); }
t.ifStatement(t.unaryExpression('!', t.identifier('_state')), t.throwStatement(t.newExpression(t.identifier('Error'), [t.stringLiteral('Contract must be initialized')])))
: t.emptyStatement(),
// let _contract = Counter._create();
t.variableDeclaration('let', [t.variableDeclarator(t.identifier('_contract'), t.callExpression(t.memberExpression(classId, t.identifier('_create')), []))]),
// Object.assign(_contract, state);
t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('Object'), t.identifier('assign')), [t.identifier('_contract'), t.identifier('_state')])),
contractMethods[method] === 'call' || contractMethods[method] === 'view' ?
// if (_state) { Object.assign(_contract, state); }
t.ifStatement(t.identifier('_state'), t.blockStatement([t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('Object'), t.identifier('assign')), [t.identifier('_contract'), t.identifier('_state')]))])) : t.emptyStatement(),
// let _args = Counter._getArgs();
t.variableDeclaration('let', [t.variableDeclarator(t.identifier('_args'), t.callExpression(t.memberExpression(classId, t.identifier('_getArgs')), []))]),
// let _result = _contract.method(args);
t.variableDeclaration('let', [t.variableDeclarator(t.identifier('_result'), t.callExpression(t.memberExpression(t.identifier('_contract'), t.identifier(method)), [t.identifier('_args')]))]),
contractMethods[method] == 'initialize' || contractMethods[method] == 'call' ?
contractMethods[method] === 'initialize' || contractMethods[method] === 'call' ?
// _contract._saveToStorage();
t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('_contract'), t.identifier('_saveToStorage')), []))
: t.emptyStatement(),
Expand Down

0 comments on commit 4a1fd14

Please sign in to comment.