@neo-one/smart-contract-compiler
Version:
NEO•ONE TypeScript smart contract compiler.
53 lines (51 loc) • 2.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.VariableDeclarationCompiler = void 0;
const tslib_1 = require("tslib");
const ts_utils_1 = require("@neo-one/ts-utils");
const typescript_1 = tslib_1.__importDefault(require("typescript"));
const types_1 = require("../helper/types");
const NodeCompiler_1 = require("../NodeCompiler");
class VariableDeclarationCompiler extends NodeCompiler_1.NodeCompiler {
constructor() {
super(...arguments);
this.kind = typescript_1.default.SyntaxKind.VariableDeclaration;
}
visitNode(sb, node, options) {
const nameNode = ts_utils_1.tsUtils.node.getNameNode(node);
const expr = ts_utils_1.tsUtils.initializer.getInitializer(node);
if (typescript_1.default.isIdentifier(nameNode)) {
sb.scope.add(ts_utils_1.tsUtils.node.getText(nameNode));
if (expr === undefined) {
if (!options.setValue) {
sb.emitHelper(node, sb.pushValueOptions(options), sb.helpers.wrapUndefined);
}
}
else {
sb.visit(expr, sb.pushValueOptions(options));
if (typescript_1.default.isIdentifier(nameNode)) {
types_1.handleTypeAssignment(sb.context, expr, node);
}
}
sb.scope.set(sb, node, options, ts_utils_1.tsUtils.node.getText(nameNode));
return;
}
if (expr === undefined) {
return;
}
if (typescript_1.default.isArrayBindingPattern(nameNode)) {
sb.emitHelper(nameNode, options, sb.helpers.arrayBinding({
type: sb.context.analysis.getType(expr),
value: expr,
}));
}
else {
sb.emitHelper(nameNode, options, sb.helpers.objectBinding({
type: sb.context.analysis.getType(expr),
value: expr,
}));
}
}
}
exports.VariableDeclarationCompiler = VariableDeclarationCompiler;
//# sourceMappingURL=VariableDeclarationCompiler.js.map