@lcap/nasl
Version:
NetEase Application Specific Language
55 lines • 2.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.transform2FrontendVariable = exports.transform2BackendVariable = void 0;
const utils_1 = require("./utils");
const transform2TypeAnnotation_1 = require("./transform2TypeAnnotation");
const transform2LogicItem_1 = require("./transform2LogicItem");
function transform2BackendVariable(node) {
if (node.declarations.length !== 1)
(0, utils_1.throwError)(`VariableDeclaration should have only one declaration`);
const declarator = node.declarations[0];
if (declarator.id.type !== 'Identifier')
(0, utils_1.throwError)(`VariableDeclarator 标识符应该是 Identifier`);
const id = declarator.id;
const variable = new utils_1.naslTypes.BackendVariable({
scope: 'request',
});
variable.name = id.name;
variable.description = (0, utils_1.fetchFromComments)(node.leadingComments);
const typeAnnotation = id.typeAnnotation?.typeAnnotation;
if (typeAnnotation) {
variable.typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation);
}
if (declarator.init) {
variable.defaultValue = new utils_1.naslTypes.DefaultValue({
expression: (0, transform2LogicItem_1.transform2LogicItem)(declarator.init, { transformType: 'attr' }),
});
}
return variable;
}
exports.transform2BackendVariable = transform2BackendVariable;
function transform2FrontendVariable(node) {
if (node.declarations.length !== 1)
(0, utils_1.throwError)(`VariableDeclaration should have only one declaration`);
const declarator = node.declarations[0];
if (declarator.id.type !== 'Identifier')
(0, utils_1.throwError)(`VariableDeclarator 标识符应该是 Identifier`);
const id = declarator.id;
const variable = new utils_1.naslTypes.FrontendVariable({
localCache: false,
});
variable.name = id.name;
variable.description = (0, utils_1.fetchFromComments)(node.leadingComments);
const typeAnnotation = id.typeAnnotation?.typeAnnotation;
if (typeAnnotation) {
variable.typeAnnotation = (0, transform2TypeAnnotation_1.transform2TypeAnnotation)(typeAnnotation);
}
if (declarator.init) {
variable.defaultValue = new utils_1.naslTypes.DefaultValue({
expression: (0, transform2LogicItem_1.transform2LogicItem)(declarator.init, { transformType: 'attr' }),
});
}
return variable;
}
exports.transform2FrontendVariable = transform2FrontendVariable;
//# sourceMappingURL=transform2Variable.js.map