serverless-fragments
Advanced tools
Comparing version 2.3.0 to 2.4.0
@@ -58,2 +58,3 @@ "use strict"; | ||
currentToken = lastVarStartToken; //reset the index to the start of the variable | ||
currentToken.index = currentToken.index - 1; //in a case when variable is replaced with an empty value | ||
} | ||
@@ -96,3 +97,3 @@ } | ||
const variable = this.extractVariable(value, startIndex, endIndex); | ||
return params.has(variable.paramName) || !!variable.defaultValue; | ||
return params.has(variable.paramName) || variable.defaultValue != undefined; | ||
} | ||
@@ -109,3 +110,3 @@ static replaceVariable(value, startIndex, endIndex, params) { | ||
} | ||
else if (variable.defaultValue) { | ||
else if (variable.defaultValue != undefined) { | ||
console.log(`\t ${variable.placeholder} => default: ${variable.defaultValue}`); | ||
@@ -119,3 +120,3 @@ value = value.replace(variable.placeholder, variable.defaultValue); | ||
//match a placeholder e.g. ${opt:stage, test} | ||
const [placeholder, , paramName, , defaultValue] = /\${(opt|self):([^,]+)(\s*,\s*(\S+)\s*)?}/gm.exec(placeholderValue); | ||
const [placeholder, , paramName, , defaultValue] = /\${(opt|self):([^,]+)(\s*,\s*(\S*)\s*)?}/gm.exec(placeholderValue); | ||
return placeholder ? { placeholder, paramName, defaultValue } : undefined; | ||
@@ -122,0 +123,0 @@ } |
@@ -146,2 +146,21 @@ "use strict"; | ||
})); | ||
it("variable with empty default", () => __awaiter(this, void 0, void 0, function* () { | ||
const content = `stage: \${opt:stage, }`; | ||
const resolved = src_1.FragmentsProcessor.resolveTokensRecursive('', content); | ||
const expectedContent = `stage: `; | ||
expect(resolved).toBe(expectedContent); | ||
})); | ||
it("variable without default", () => __awaiter(this, void 0, void 0, function* () { | ||
const content = `stage: \${opt:stage}`; | ||
const resolved = src_1.FragmentsProcessor.resolveTokensRecursive('', content); | ||
const expectedContent = `stage: \${opt:stage}`; | ||
expect(resolved).toBe(expectedContent); | ||
})); | ||
it("variable with default followed by variable", () => __awaiter(this, void 0, void 0, function* () { | ||
const content = `\${opt:serviceName, }\${opt:tableName}`; | ||
const params = new Map([['tableName', 'webhook']]); | ||
const resolved = src_1.FragmentsProcessor.resolveTokensRecursive('', content, params); | ||
const expectedContent = `webhook`; | ||
expect(resolved).toBe(expectedContent); | ||
})); | ||
it("missing variable value with default", () => __awaiter(this, void 0, void 0, function* () { | ||
@@ -148,0 +167,0 @@ const content = `stage: \${opt:stage, 'test'}`; |
{ | ||
"name": "serverless-fragments", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"main": "dist/src/index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
38177
617