Comparing version 3.0.91 to 3.0.92
{ | ||
"name": "fable", | ||
"version": "3.0.91", | ||
"version": "3.0.92", | ||
"description": "An entity behavior management and API bundling library.", | ||
@@ -5,0 +5,0 @@ "main": "source/Fable.js", |
@@ -47,2 +47,7 @@ const libFableServiceBase = require('fable-serviceproviderbase'); | ||
addPatternBoth(pPatternStart, pPatternEnd, pParser, pParserPromise) | ||
{ | ||
return this.WordTree.addPatternBoth(pPatternStart, pPatternEnd, pParser, pParserPromise); | ||
} | ||
/** | ||
@@ -49,0 +54,0 @@ * Parse a string with the existing parse tree |
@@ -108,3 +108,3 @@ /** | ||
// If this last character is the end of the pattern, parse it. | ||
if (pParserState.Pattern.hasOwnProperty('Parse')) | ||
if (pParserState.Pattern.hasOwnProperty('Parse') && (!pParserState.Pattern.isAsync || pParserState.Pattern.isBoth)) | ||
{ | ||
@@ -115,2 +115,7 @@ // Run the function | ||
} | ||
else | ||
{ | ||
console.log(`MetaTemplate: The pattern ${pParserState.Pattern.PatternStartString} is asynchronous and cannot be used in a synchronous parser.`); | ||
return this.resetOutputBuffer(pParserState); | ||
} | ||
} | ||
@@ -148,5 +153,5 @@ else if (pParserState.PatternStartNode.PatternEnd.hasOwnProperty(pCharacter)) | ||
{ | ||
if (pParserState.Pattern.isAsync) | ||
if (pParserState.Pattern.isAsync && !pParserState.Pattern.isBoth) | ||
{ | ||
this.log.error(`MetaTemplate: The pattern ${pParserState.Pattern.PatternStartString} is asynchronous and cannot be used in a synchronous parser.`); | ||
console.log(`MetaTemplate: The pattern ${pParserState.Pattern.PatternStartString} is asynchronous and cannot be used in a synchronous parser.`); | ||
this.resetOutputBuffer(pParserState); | ||
@@ -221,3 +226,3 @@ } | ||
// Trim the start and end tags off the output buffer now | ||
if (pParserState.Pattern.isAsync) | ||
if (pParserState.Pattern.isAsync && !pParserState.Pattern.isBoth) | ||
{ | ||
@@ -238,2 +243,18 @@ // Run the function | ||
} | ||
else if (pParserState.Pattern.isAsync && pParserState.Pattern.isBoth) | ||
{ | ||
// Run the function when both async and non async were provided with the pattern | ||
return pParserState.Pattern.ParseAsync(pParserState.OutputBuffer.substr(pParserState.Pattern.PatternStartString.length, pParserState.OutputBuffer.length - (pParserState.Pattern.PatternStartString.length+pParserState.Pattern.PatternEndString.length)), pData, | ||
(pError, pAsyncOutput) => | ||
{ | ||
if (pError) | ||
{ | ||
console.log(`Precedent ERROR: Async template error happened parsing ${pParserState.Pattern.PatternStart} ... ${pParserState.Pattern.PatternEnd}: ${pError}`); | ||
} | ||
pParserState.OutputBuffer = pAsyncOutput; | ||
this.resetOutputBuffer(pParserState); | ||
return fCallback(); | ||
}); | ||
} | ||
else | ||
@@ -240,0 +261,0 @@ { |
@@ -104,9 +104,25 @@ /** | ||
/** Add a Pattern to the Parse Tree | ||
* @method addPattern | ||
* @method addPatternAsync | ||
* @param {Object} pPatternStart - The starting string for the pattern (e.g. "${") | ||
* @param {string} pPatternEnd - The ending string for the pattern (e.g. "}") | ||
* @param {function} fParserAsync - The function to parse if this is the matched pattern, once the Pattern End is met. If this is a string, a simple replacement occurs. | ||
* @return {bool} True if adding the pattern was successful | ||
*/ | ||
addPatternAsync (pPatternStart, pPatternEnd, fParserAsync) | ||
{ | ||
let tmpLeaf = this.addPattern(pPatternStart, pPatternEnd, fParserAsync); | ||
if (tmpLeaf) | ||
{ | ||
tmpLeaf.isAsync = true; | ||
} | ||
} | ||
/** Add a Pattern to the Parse Tree | ||
* @method addPatternBoth | ||
* @param {Object} pPatternStart - The starting string for the pattern (e.g. "${") | ||
* @param {string} pPatternEnd - The ending string for the pattern (e.g. "}") | ||
* @param {function} fParser - The function to parse if this is the matched pattern, once the Pattern End is met. If this is a string, a simple replacement occurs. | ||
* @return {bool} True if adding the pattern was successful | ||
*/ | ||
addPatternAsync (pPatternStart, pPatternEnd, fParser) | ||
addPatternBoth (pPatternStart, pPatternEnd, fParser, fParserAsync) | ||
{ | ||
@@ -117,2 +133,5 @@ let tmpLeaf = this.addPattern(pPatternStart, pPatternEnd, fParser); | ||
tmpLeaf.isAsync = true; | ||
tmpLeaf.isBoth = true; | ||
// When a leaf has both async and non-async versions of the functions, we store the async in fParserAsync. | ||
tmpLeaf.ParseAsync = fParserAsync; | ||
} | ||
@@ -119,0 +138,0 @@ } |
@@ -40,2 +40,12 @@ /** | ||
}); | ||
pModule.addPatternBoth('<~', '~>', | ||
(pHash, pData) => | ||
{ | ||
return `Non-Async Jellyfish called for pData which is [${pData}] with a hash of [${pHash}]` | ||
}, | ||
(pHash, pData, fCallback)=> | ||
{ | ||
return fCallback(null, `Async Jellyfish called for pData which is [${pData}] with a hash of [${pHash}]`); | ||
}); | ||
@@ -165,2 +175,21 @@ }; | ||
( | ||
'Passing both Async and Non-async Function', | ||
(fDone) => | ||
{ | ||
let tmpTestString = 'The <^SomeValue^> and <~JELLY FISH~> pData and Async <%AsyncThe Funny String%> up in here and a $comment$ as well.'; | ||
let tmpExpectedResultAsync = 'The hash of [SomeValue] from pData is AirbornLight and Async Jellyfish called for pData which is [[object Object]] with a hash of [JELLY FISH] pData and Async ASYNC DATA IS [The Funny String] up in here and a comment as well.'; | ||
let tmpExpectedResult = 'The hash of [SomeValue] from pData is AirbornLight and Non-Async Jellyfish called for pData which is [[object Object]] with a hash of [JELLY FISH] pData and Async <%AsyncThe Funny String%> up in here and a comment as well.'; | ||
let testMetaTemplate = loadMetaTemplateModule(); | ||
configMetaTemplate(testMetaTemplate); | ||
let tmpNonAsyncResult = testMetaTemplate.parseString(tmpTestString, {SomeValue:'AirbornLight'}); | ||
Expect(tmpNonAsyncResult).to.equal(tmpExpectedResult); | ||
let tmpResult = testMetaTemplate.parseString(tmpTestString, {SomeValue:'AirbornLight'}, | ||
(pError, pValue) => | ||
{ | ||
Expect(pValue).to.equal(tmpExpectedResultAsync); | ||
return fDone(); | ||
}); | ||
} | ||
); test | ||
( | ||
'Bad pattern start parameter...', | ||
@@ -167,0 +196,0 @@ (fDone) => |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
12799002
18738