Comparing version 3.3.1 to 4.0.0
@@ -11,3 +11,3 @@ "use strict"; | ||
const Node_1 = require("./Node"); | ||
const SymbolSpecs_1 = require("./SymbolSpecs"); | ||
const Import_1 = require("./Import"); | ||
const prettier_1 = __importStar(require("prettier")); | ||
@@ -40,3 +40,3 @@ const is_plain_object_1 = require("./is-plain-object"); | ||
assignAliasesIfNeeded(defs, imports, ourModulePath); | ||
const importPart = SymbolSpecs_1.emitImports(imports, ourModulePath); | ||
const importPart = Import_1.emitImports(imports, ourModulePath); | ||
const bodyPart = this.generateCode(); | ||
@@ -64,3 +64,3 @@ return maybePrettyWithConfig(importPart + '\n' + bodyPart); | ||
const placeholder = todo.shift(); | ||
if (placeholder instanceof SymbolSpecs_1.SymbolSpec) { | ||
if (placeholder instanceof Import_1.Import) { | ||
imports.push(placeholder); | ||
@@ -177,4 +177,4 @@ } | ||
imports.forEach((i) => { | ||
if (i instanceof SymbolSpecs_1.ImportsName && | ||
!(SymbolSpecs_1.sameModule(i.source, ourModulePath) || (i.definedIn && SymbolSpecs_1.sameModule(i.definedIn, ourModulePath)))) { | ||
if (i instanceof Import_1.ImportsName && | ||
!(Import_1.sameModule(i.source, ourModulePath) || (i.definedIn && Import_1.sameModule(i.definedIn, ourModulePath)))) { | ||
if (defNames.has(i.value)) { | ||
@@ -181,0 +181,0 @@ // Look for an existing alias |
@@ -1,2 +0,2 @@ | ||
import { SymbolSpec } from './SymbolSpecs'; | ||
import { Import } from './Import'; | ||
import { Code, Def } from './Code'; | ||
@@ -6,2 +6,3 @@ import { Node } from './Node'; | ||
export { Code } from './Code'; | ||
export { Import } from './Import'; | ||
/** A template literal to format code and auto-organize imports. */ | ||
@@ -13,3 +14,3 @@ export declare function code(literals: TemplateStringsArray, ...placeholders: unknown[]): Code; | ||
definedIn?: string; | ||
}): SymbolSpec; | ||
}): Import; | ||
/** Defines `symbol` as being locally defined in the file, to avoid import collisions. */ | ||
@@ -16,0 +17,0 @@ export declare function def(symbol: string): Def; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const SymbolSpecs_1 = require("./SymbolSpecs"); | ||
const Import_1 = require("./Import"); | ||
const Code_1 = require("./Code"); | ||
@@ -9,2 +9,4 @@ const Node_1 = require("./Node"); | ||
exports.Code = Code_2.Code; | ||
var Import_2 = require("./Import"); | ||
exports.Import = Import_2.Import; | ||
/** A template literal to format code and auto-organize imports. */ | ||
@@ -28,3 +30,3 @@ function code(literals, ...placeholders) { | ||
function imp(spec, opts = {}) { | ||
const sym = SymbolSpecs_1.SymbolSpec.from(spec); | ||
const sym = Import_1.Import.from(spec); | ||
if (opts && opts.definedIn) { | ||
@@ -31,0 +33,0 @@ sym.definedIn = opts.definedIn; |
{ | ||
"name": "ts-poet", | ||
"version": "3.3.1", | ||
"version": "4.0.0", | ||
"description": "code generation DSL for TypeScript", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -103,3 +103,3 @@ | ||
Sometimes when generating larger, intricate output, you want to conditionally include helper methods. I.e. have a `convertTimestamps` function declared at the top of your module, but only actually include that function is some other part of the output actually uses timestamps (which might depend on the specific input/schema you're generating code against). | ||
Sometimes when generating larger, intricate output, you want to conditionally include helper methods. I.e. have a `convertTimestamps` function declared at the top of your module, but only actually include that function if some other part of the output actually uses timestamps (which might depend on the specific input/schema you're generating code against). | ||
@@ -110,3 +110,5 @@ ts-poet supports this with a `conditionalOutput` method: | ||
const convertTimestamps = conditionalOutput( | ||
// The string to output at the usage site | ||
"convertTimestamps", | ||
// The code to conditionally output if convertTimestamps is used | ||
code`function convertTimestamps() { ...impl... }`, | ||
@@ -118,5 +120,7 @@ ); | ||
if (f.type === "timestamp") { | ||
// Using the convertTimestamps const marks it as used in our output | ||
return code`${convertTimestamps}(f)`; | ||
} | ||
})} | ||
// The .ifUsed result will be empty unless `convertTimestamps` has been marked has used | ||
${convertTimestamps.ifUsed} | ||
@@ -123,0 +127,0 @@ `; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
98171
31
1801
144