ask-cli-x
Version:
Alexa Skills Kit (ASK) Command Line Interfaces
41 lines (40 loc) • 2.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isNamedCallExpression = exports.getVisibleLocalVariableNames = exports.getLastInterationOrCorrectionExpectedBlock = void 0;
const acdl_1 = require("@alexa/acdl");
const getLastInterationOrCorrectionExpectedBlock = (module) => {
var _a, _b, _c, _d, _e;
const [last] = (_b = [...((_a = module.expressions) !== null && _a !== void 0 ? _a : [])]) === null || _b === void 0 ? void 0 : _b.reverse();
if (last && last instanceof acdl_1.InteractionDeclaration) {
const [last_c] = (_e = [...((_d = (_c = last.scope) === null || _c === void 0 ? void 0 : _c.expressions) !== null && _d !== void 0 ? _d : [])]) === null || _e === void 0 ? void 0 : _e.reverse();
if (last_c) {
if (last_c && last_c instanceof acdl_1.Correction) {
return last_c.expected;
}
}
return last.scope;
}
return;
};
exports.getLastInterationOrCorrectionExpectedBlock = getLastInterationOrCorrectionExpectedBlock;
/**
* Finds all visible variable names at this point and their properties up to a depth. Only looks at NameDeclarations.
*/
const getVisibleLocalVariableNames = (checker, node, depth) => {
const lexicalScope = checker.getVisibleNames(node);
const _depth = depth || 1;
return lexicalScope
? [...lexicalScope.entries()]
.filter((entry) => typeof entry[1] === "object" && entry[1] instanceof acdl_1.NameDeclaration)
.reduce((vars, [key, value]) => {
var _a, _b, _c;
const props = (_c = (_depth >= 1 ? (_b = (_a = checker.getType(value)) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.map((p) => `${key}.${p.name}`) : undefined)) !== null && _c !== void 0 ? _c : [];
return [...vars, key, ...props];
}, [])
: [];
};
exports.getVisibleLocalVariableNames = getVisibleLocalVariableNames;
const isNamedCallExpression = (expression) => {
return expression.expression instanceof acdl_1.Call;
};
exports.isNamedCallExpression = isNamedCallExpression;