jsii-pacmak
Version:
A code generation framework for jsii backend languages
39 lines • 1.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeLiteralTypeReference = makeLiteralTypeReference;
exports.literalTypeReference = literalTypeReference;
exports.isLiteralTypeReference = isLiteralTypeReference;
const spec = require("@jsii/spec");
const LITERAL_TYPE_PREFIX = '$lit:';
/**
* Make a type reference that references exactly a literal.
*
* This is useful if we don't want to reference a real type but a locally bound
* type parameter.
*
* This is a slightly hacky way to get the rendering functio to render a
* literal string, without looking it up. It gets us to embed the notion of
* rendering literal type parameters in the existing jsii spec without having to
* explicitly model it only for the purpose of a couple of code generators.
*/
function makeLiteralTypeReference(typeParameterName) {
return { fqn: `${LITERAL_TYPE_PREFIX}${typeParameterName}` };
}
/**
* Return the type parameter name if the type reference is a type literal
*/
function literalTypeReference(x) {
if (!spec.isNamedTypeReference(x)) {
return undefined;
}
return x.fqn.startsWith(LITERAL_TYPE_PREFIX)
? x.fqn.slice(LITERAL_TYPE_PREFIX.length)
: undefined;
}
/**
* Whether the given type is a literal type reference
*/
function isLiteralTypeReference(x) {
return literalTypeReference(x) !== undefined;
}
//# sourceMappingURL=type-literals.js.map