Files
codeql-action/node_modules/ts-poet/build/ConditionalOutput.js
Angela P Wen a196a714b8 Bump artifact dependencies if CODEQL_ACTION_ARTIFACT_V2_UPGRADE enabled (#2482)
Co-authored-by: Andrew Eisenberg <aeisenberg@github.com>
Co-authored-by: Henry Mercer <henrymercer@github.com>
2024-10-01 09:59:05 -07:00

57 lines
1.7 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MaybeOutput = exports.ConditionalOutput = void 0;
const Node_1 = require("./Node");
/**
* Helps output conditional helper methods.
*
* The `ConditionalOutput` concept is split into a usage site and a declaration
* site, i.e. declaring a `function someHelper() { ... }`, and calling it
* like `someHelper()`.
*
* While generating code, you can make usage says by using `someHelper` as
* a placeholder, and then output the declaration with `someHelper.ifUsed`
* to output the declaration conditionally only if `someHelper` has been
* seen in the tree.
*
* ```typescript
* const someHelper = conditionalOutput(
* "someHelper",
* code`function someHelper() { return 1 } `
* );
*
* const code = code`
* ${someHelper}
*
* ${someHelper.ifUsed}
* `
* ```
*/
class ConditionalOutput extends Node_1.Node {
// A given ConditionalOutput const could be used in multiple code
// parents, and so we don't want to use instance state to store
// "should I be output or not", b/c it depends on the containing tree.
constructor(usageSiteName, declarationSiteCode) {
super();
this.usageSiteName = usageSiteName;
this.declarationSiteCode = declarationSiteCode;
}
get childNodes() {
return [this.declarationSiteCode];
}
toCodeString() {
return this.usageSiteName;
}
get ifUsed() {
return new MaybeOutput(this, this.declarationSiteCode);
}
}
exports.ConditionalOutput = ConditionalOutput;
class MaybeOutput {
constructor(parent, code) {
this.parent = parent;
this.code = code;
}
}
exports.MaybeOutput = MaybeOutput;